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?: ?? }
Most image when imported into server-side TypeScript are strings.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With