Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.
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

Description

@ndh103

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"]
}

Activity

GMKR

GMKR commented on Oct 2, 2021

@GMKR

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

ndh103 commented on Oct 3, 2021

@ndh103
Author

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

sapphi-red commented on Oct 3, 2021

@sapphi-red
Sponsor

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

added a commit that references this issue on Oct 3, 2021
ndh103

ndh103 commented on Oct 3, 2021

@ndh103
Author

@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

sapphi-red commented on Oct 3, 2021

@sapphi-red
Sponsor

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

ndh103 commented on Oct 3, 2021

@ndh103
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ndh103@GMKR@johnsoncodehk@sapphi-red

        Issue actions

          vue-tsc --noEmit show error when using Svg as component · Issue #80 · johnsoncodehk/vue-tsc