question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript support?

See original GitHub issue

I’m using nuxt with typescript (nuxt-property-decorator), when import svg:

<script lang="ts">
import { Component, Vue } from 'nuxt-property-decorator'
import Logo from '@/assets/svg/logo.svg'

@Component({
  components: {
    Logo
  }
})
class Def extends Vue {}
export default Def
</script>

I’m getting error: Cannot find module '@/assets/svg/logo.svg'.Vetur(2307)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
kevinmarreccommented, Aug 13, 2019

@manniL Yes I have !

@webcoderkz You need a file in root directory or in a @types directory (in both cases TypeScript compiler will take it into account).

It needs to be a .d.ts file (example: svg-shims.d.ts)

With content :

declare module '*.svg' {
  const content: any
  export default content
}

It makes TypeScript aware of what type should resolve a SVG file, fixing errors when importing .svg in TypeScript files.

PS : I will add a note in new TypeScript docs about non-TS/JS imports

1reaction
Kapcashcommented, Jun 1, 2021

@webcoderkz You have to declare the svg?inline in the declaration file as well:

declare module '*.svg?inline' {
  const content: any
  export default content
}

declare module '*.svg' {
  const content: any
  export default content
}

It works fine for me 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript: JavaScript With Syntax For Types.
TypeScript extends JavaScript by adding types to the language. TypeScript speeds up your development experience by catching errors and providing fixes ...
Read more >
TypeScript - Wikipedia
TypeScript supports definition files that can contain type information of existing JavaScript libraries, much like C++ header files can describe the ...
Read more >
TypeScript Programming with Visual Studio Code
Visual Studio Code includes TypeScript language support but does not include the TypeScript compiler, tsc . You will need to install the TypeScript...
Read more >
TypeScript | WebStorm Documentation - JetBrains
WebStorm supports developing, running, and debugging TypeScript source code. ... Learn more from Compiling TypeScript into JavaScript.
Read more >
TypeScript support in Svelte - Learn web development
First-class TypeScript support has been Svelte's most requested feature for quite some time. Thanks to the hard work of the Svelte team, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found