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

tsx中使用unplugin-vue-components导入的vue编写的组件会有类型错误 #674

Open bigWhiteWhite opened 11 months ago

bigWhiteWhite commented 11 months ago

Describe the bug

"unplugin-vue-components": "^0.25.1"

// vite.config.ts Components({ dts: true, dirs: ['components'], extensions: ['vue', 'tsx', 'jsx'], resolvers: [VantResolver()], include: [/.vue$/, /.vue\?vue/, /.md$/, /.tsx/, /.jsx/] })

// index.tsx export default defineComponent({ setup(props, { emit }) { }, render() { return } })

实际上是可以运行的,组件也有正常渲染,但是ts找不到名称“AppSkeleton”的组件,在vue文件中是正常的,但是在tsx文件中会报这样的类型错误。 生成的components.d.ts文件如下: export {} declare module 'vue' { export interface GlobalComponents { AppDrag: typeof import('./components/AppDrag.vue')['default'] AppSkeleton: typeof import('./components/AppSkeleton.vue')['default'] AppUpload: typeof import('./components/AppUpload.vue')['default'] Banner: typeof import('./components/Banner/index.vue')['default'] NavBarOne: typeof import('./components/NavBar/NavBarOne.vue')['default'] NavBarThree: typeof import('./components/NavBar/NavBarThree.vue')['default'] SvgIcon: typeof import('./components/SvgIcon/index.vue')['default'] VanSkeleton: typeof import('vant/es')['Skeleton'] } }

Reproduction

生产

System Info

谷歌浏览器
"vue": "^3.2.39",
"unplugin-vue-components": "^0.25.1",
"typescript": "^4.9.5",

Used Package Manager

npm

Validations

bigWhiteWhite commented 11 months ago

Describe the bug

"unplugin-vue-components": "^0.25.1"

// vite.config.ts Components({ dts: true, dirs: ['components'], extensions: ['vue', 'tsx', 'jsx'], resolvers: [VantResolver()], include: [/.vue$/, /.vue?vue/, /.md$/, /.tsx/, /.jsx/] })

// index.tsx export default defineComponent({ setup(props, { emit }) { }, render() { return } })

实际上是可以运行的,组件也有正常渲染,但是ts找不到名称“AppSkeleton”的组件,在vue文件中是正常的,但是在tsx文件中会报这样的类型错误。 生成的components.d.ts文件如下: export {} declare module 'vue' { export interface GlobalComponents { AppDrag: typeof import('./components/AppDrag.vue')['default'] AppSkeleton: typeof import('./components/AppSkeleton.vue')['default'] AppUpload: typeof import('./components/AppUpload.vue')['default'] Banner: typeof import('./components/Banner/index.vue')['default'] NavBarOne: typeof import('./components/NavBar/NavBarOne.vue')['default'] NavBarThree: typeof import('./components/NavBar/NavBarThree.vue')['default'] SvgIcon: typeof import('./components/SvgIcon/index.vue')['default'] VanSkeleton: typeof import('vant/es')['Skeleton'] } }

Reproduction

生产

System Info

谷歌浏览器
"vue": "^3.2.39",
"unplugin-vue-components": "^0.25.1",
"typescript": "^4.9.5",

Used Package Manager

npm

Validations

  • [x] Follow our Code of Conduct
  • [x] Read the Contributing Guide.
  • [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • [x] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • [x] The provided reproduction is a minimal reproducible of the bug.
lishaobos commented 11 months ago

兄弟,帮忙提供个 git 仓库,确保我能一次性解决问题

toosui commented 10 months ago

这可能和编辑器类型检测有关系

cumt-robin commented 9 months ago

jsx/tsx不支持,手动引入

JounQin commented 8 months ago

jsx/tsx不支持,手动引入

但是它在 components.d.ts 里自动生成了就很蛋疼了。。。

lixiaofa commented 6 months ago

兄弟,帮忙提供个 git 仓库,确保我能一次性解决问题

see https://github.com/lixiaofa/test636 是挺恶心的,在 components.d.ts 里自动生成了 @lishaobos

QAQLC commented 3 months ago

我有一个想法,不知道可行不可行,那就是在生成componets.d.ts文件中,在生成一个类型,比如 declare global { AppSkeleton: typeof import('./components/AppSkeleton.vue')['default'] }

这样就可以找到了