18 June 2022

In react you can import image and use it in JSX, so that the compiler knows to load the asset. Apparently by default TypeScript doesn't support image files to be loaded. So you have to add new declarations to "declaration.d.ts". The error that I got was "TS2307: Cannot find module '/assets/image.png' or its corresponding type declarations."

Source code viewer
  1. // declaration.d.ts
  2. declare module "*.png" {
  3. const value: any;
  4. export default value;
  5. }
Programming Language: ECMAScript