How to add the type for Image with TypeScript?

Sometimes, we want to add the type for Image with TypeScript.

In this article, we’ll look at how to add the type for Image with TypeScript.

How to add the type for Image with TypeScript?

To add the type for Image with TypeScript, we should use the HTMLImageElement for Image instances.

For instance, we write

const image: HTMLImageElement = new Image();

to set image to the HTMLImageElement.

Image files selected from an input should have the File type and URL strings for images should have the string type.

Conclusion

To add the type for Image with TypeScript, we should use the HTMLImageElement for Image instances.