Categories
- Post authorBy John Au-Yeung
- Post dateMarch 20, 2022
- No Comments on How to allow image import with TypeScript?
Spread the love
Sometimes, we want to allow image import with TypeScript.
In this article, we’ll look at how to allow image import with TypeScript.
How to allow image import with TypeScript?
To allow image import with TypeScript, we can use declare
to declare the type for image files.
For instance, we write
declare module "*.png" { const value: any; export = value;}
to declare the type for modules with the .png
extension.
We just allow any property to be exported with
const value: any;export = value;
And then we can import .png
files without errors.
Conclusion
To allow image import with TypeScript, we can use declare
to declare the type for image files.
Related Posts
How to import other TypeScript files?
Sometimes, we want to import other TypeScript files. In this article, we'll look at how…
How to import moment.js with TypeScript?
Sometimes, we want to import moment.js with TypeScript. In this article, we'll look at how…
How to declare and import TypeScript interfaces in a separate file?
Sometimes, we want to declare and import TypeScript interfaces in a separate file. In this…
By John Au-Yeung
Web developer specializing in React, Vue, and front end development.