nuxt-community / svg-module

Super simple svg loading module for Nuxt.js
MIT License
340 stars 35 forks source link

Typescript error #29

Closed filipwronski closed 4 years ago

filipwronski commented 4 years ago

I'm using svg as module, code work and correct icon is visible, but I have typescript error: Cannot find module '~/assets/img/icons/close-circle.svg?inline'. Any Idea how to fix it? I have already added svg to index.d.ts

declare module '*.svg' {
    const content: string
    export default content
}
gotenxds commented 4 years ago

It should be in a file name custom.d.ts

marcoborsoi commented 4 years ago

Hello @filipwronski, @sam3d I'm having the same issue and I was wondering if you were able to fix it. Thank you!

marcoborsoi commented 4 years ago

For those looking for a solution, this worked for me:

  1. Create a file named custom.d.ts on @types directory under root: declare module '*.svg';

  2. On tsconfig.json, add: "files": [ "@types/custom.d.ts" ]

RozbehSharahi commented 4 years ago

@filipwronski Since you are doing ?inline your IDE is probably not mapping your import to the declaration.

What i did on my project was:

declare module '*.svg?inline' {
  ...
}

I hope this helps

mbledkowski commented 2 years ago

@RozbehSharahi Where do you put this line?

Ic3m4n34 commented 2 years ago

@mbledkowski Create a file called svg-shim.d.ts or something like it in your @types or types folder. Put

declare module '*.svg?inline' {
}

inside.