Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In TypeScript, What is the type of Image?

I'm declaring an interface which will contains image also. What type do i need to give to it.

export interface AdInterface {     email: string;     mobile: number;     image?:   ?? } 
like image 833
Seenu S Avatar asked Jan 22 '17 14:01

Seenu S


People also ask

What is the type of an image in TypeScript?

Most image when imported into server-side TypeScript are strings.

What is type of in TypeScript?

TypeScript adds a typeof operator you can use in a type context to refer to the type of a variable or property: let s = "hello"; let n : typeof s ; let n: string. This isn't very useful for basic types, but combined with other type operators, you can use typeof to conveniently express many patterns.

How do you use images in TypeScript?

To add the type for Image with TypeScript, we should use the HTMLImageElement for Image instances. 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.

What type is SVG TypeScript?

SVG elements is SVGElement which is documented on MDN. Since TypeScript 3. x, TypeScript's "standard library" of typings for the HTML DOM includes the SVG DOM interfaces in lib/lib.


1 Answers

If your image property contains ...

Image used as <img> element

image?: HTMLImageElement 

URL to image.

image?: String 

Image as file from <input> element

image?: File 

like image 122
Misaz Avatar answered Sep 18 '22 19:09

Misaz