I have typescript error while adding props to Svg as ReactComponent- type is not assignable to type 'IntrinsicAttributes'. Plugin: vite-plugin-svgr
vite.config.ts -
svgr({
exportAsDefault: true,
svgrOptions: {
icon: true,
},
})
Added
"types" : "vite-plugin-svgr/client"
to ts compiler and I import svg like
import Icon from "./path"
Any suggestions?
For me i didn't create any custom file, you just need
"compilerOptions":
{
[...rest...]
"types": ["vite-plugin-svgr/client"] <--- this line
},
import svgr from "vite-plugin-svgr";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), svgr()],
});
import { ReactComponent as MySuperCustomIconComponent } from "../assets/logo.svg";
and simply use it
<MySuperCustomIconComponent/>
There is a declaration helper that you just need to append to your vite-env.d.ts file. I had compatibility issues with other solutions.
// vite-env.d.ts
// ...
/// <reference types="vite-plugin-svgr/client" />
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