unplugin-vue-components icon indicating copy to clipboard operation
unplugin-vue-components copied to clipboard

fix: tsx component type declaration

Open lishaobos opened this issue 2 years ago • 6 comments

Description

make auto imported component work with tsx

Linked Issues

https://github.com/antfu/unplugin-vue-components/issues/669

Additional context

lishaobos avatar Aug 07 '23 10:08 lishaobos

It should be done under a flag. As it provides global types, while this plugin only transform Vue's complication result, which will create misalignment between types and actual behaviour

antfu avatar Aug 08 '23 10:08 antfu

@antfu i have an idea.

  1. add options.dtsGlobal: boolean
  2. add options.dts type: boolean | string | { path: string; global: boolean }

lishaobos avatar Aug 08 '23 10:08 lishaobos

I solved the problem in this way:

created a 'components-tsc.d.ts' file manually

export {}

declare global {
    const NButton: typeof import('naive-ui')['NButton']
}

and put it in the tsconfig.json's include prop

{
  "include": ["env.d.ts", "src/**/*", "src/**/*.vue", "auto-imports.d.ts", "components-tsx.d.ts"],
  ...
}

cmdyu avatar Sep 14 '23 02:09 cmdyu