Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

vue-tsc --noEmit show error when using Svg as component #80

Closed
ndh103 opened this issue Oct 2, 2021 · 6 comments
Closed

vue-tsc --noEmit show error when using Svg as component #80

ndh103 opened this issue Oct 2, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@ndh103
Copy link

ndh103 commented Oct 2, 2021

Vue Language Features (Volar) version v0.27.27
TypeScript Vue Plugin (Volar) version v0.27.27

I am using https://github.com/jpkleemans/vite-svg-loader to load svg file as component

import ArrowLeftIcon from '@/assets/arrow-left-icon.svg?component'
usage in template

<div class="app-action-link" @click="goBack()">
      <ArrowLeftIcon class="h-4 w-4 inline-block" /> back
    </div>

vue-tsc show error in <ArrowLeftIcon

JSX element type '__VLS_9' does not have any construct or call signatures.ts(2604)
(property) ArrowLeftIcon: Component<any, any, any, ComputedOptions, MethodOptions>

my tsconfig

{
  "compilerOptions": {
    "target": "esnext",
    "useDefineForClassFields": true,
    "module": "esnext",
    "moduleResolution": "node",
    "strict": true,
    "jsx": "preserve",
    "sourceMap": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "lib": ["esnext", "dom"],
    "strictNullChecks": false,
    "noImplicitAny": false,
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
}

@GMKR
Copy link

GMKR commented Oct 2, 2021

Create components.d.ts file (https://github.com/johnsoncodehk/volar#using) in src folder.

In my case it is autogenerated by unplugin-vue-components in root folder, including it in tsconfig.json worked for me.

here is my tsconfig

{
  "compilerOptions": {
    "baseUrl": ".",
    "target": "esnext",
    "useDefineForClassFields": true,
    "module": "esnext",
    "moduleResolution": "node",
    "strict": true,
    "jsx": "preserve",
    "sourceMap": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "lib": ["esnext", "dom"],
    "paths": {
      "~/*": ["src/*"]
    }
  },
  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "components.d.ts"]
}

@ndh103
Copy link
Author

ndh103 commented Oct 3, 2021

I've tried and it is not working for me.
Reference to the other issue in Volar here also with the version 0.27.27
vuejs/language-tools#547

@sapphi-red
Copy link

Using DefineComponent instead of Component with declare module '*.svg?component' worked for me.

johnsoncodehk added a commit to vuejs/language-tools that referenced this issue Oct 3, 2021
@johnsoncodehk johnsoncodehk added the bug Something isn't working label Oct 3, 2021
@ndh103
Copy link
Author

ndh103 commented Oct 3, 2021

@johnsoncodehk This is still not working with version 0.27.28

@sapphi-red can you tell in more detail? in what find you make changes?

@sapphi-red
Copy link

Instead of adding /// <reference types="vite-svg-loader" /> to src/vite-env.d.ts, I added

declare module '*.svg?component' {
  import { DefineComponent } from 'vue'
  const src: DefineComponent
  export default src
}

to it.

@ndh103
Copy link
Author

ndh103 commented Oct 3, 2021

@sapphi-red thank you, it works like a charm!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants