Hope! This will help someone.
Actually, I tried all the steps but one thing we have to understand, you have to create the custom.d.ts file into the corresponding SVG import folder.
ts config file
{
"compilerOptions": {
"target": "ES6",
"jsx": "react",
"module": "ESNext",
"moduleResolution": "Node",
"baseUrl": "./",
"paths": {
"@components/*": ["src/components/*"],
"@styles/*": ["src/styles/*"],
"@static/*": ["src/static/*"]
},
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"isolatedModules": true
},
"include": ["src/**/*", "src/static/optional.d.ts"],
"exclude": ["node_modules", "build"]
}
optional.d.ts
declare module '*.svg' {
import * as React from 'react';
export const ReactComponent: React.FunctionComponent<React.SVGProps<
SVGSVGElement
> & { title?: string }>;
const src: string;
export default src;
}
Finally the common export file:
import Logo from './images/logo.svg';
import BellDot from './images/bell-dot.svg';
import Logout from './images/logout.svg';
import pageNotFound from './images/page-not-found.png';
export {
Logo,
BellDot,
pageNotFound,
Logout
}
For a better idea:
import
statement. Perhaps Webpack is what's allowing this in your JavaScript, but it's not doing the same magic in TypeScript files. (I don't think that TypeScript itself knows what to do here.) – Whimsicalconst logo = require("./logo.svg");
or simply ignore the error. (I believe TS should still be outputting the right code.) – Whimsicalconst logo = require("./logo.svg") as string;
– Stuimport
. For a newbie like me, these things discourage me. Aren't we in 2020 where "auto-configuration" should be a norm ? – Monumentalize<img src={path} />
? – Paco