unplugin / unplugin-vue-components

📲 On-demand components auto importing for Vue
https://www.npmjs.com/package/unplugin-vue-components
MIT License
3.68k stars 342 forks source link

fix: tsx component type declaration #673

Open lishaobos opened 11 months ago

lishaobos commented 11 months ago

Description

make auto imported component work with tsx

Linked Issues

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

Additional context

antfu commented 11 months ago

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

lishaobos commented 11 months ago

@antfu i have an idea.

  1. add options.dtsGlobal: boolean
  2. add options.dts type: boolean | string | { path: string; global: boolean }
cmdyu commented 10 months ago

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