Skip to content

How to auto-import components in .tsx? files #836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
5 tasks done
atox996 opened this issue Apr 15, 2025 · 4 comments
Open
5 tasks done

How to auto-import components in .tsx? files #836

atox996 opened this issue Apr 15, 2025 · 4 comments

Comments

@atox996
Copy link

atox996 commented Apr 15, 2025

Describe the bug

When using unplugin-vue-components to auto-import components, we noticed that the generated components.d.ts only declares global components for the vue module, for example:

declare module 'vue' {
  export interface GlobalComponents {
    TForm: typeof import('tdesign-vue-next')['Form'];
  }
}

This works well for .vue files, but in .tsx or .ts files using JSX, TypeScript still reports an error:

<TForm>...</TForm>
// ❌ Cannot find name 'TForm'. ts(2552)

This plugin works great in Vue projects — we hope it can become even better with improved TSX support in the future!

Reproduction

none

System Info

windows

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@userquin
Copy link
Member

shouldn't be <TForm> instead <Form>

@atox996
Copy link
Author

atox996 commented Apr 16, 2025

shouldn't be <TForm> instead <Form>

This is just a description error, but the actual result is still an error due to the reason of declare module 'vue'

@userquin
Copy link
Member

userquin commented Apr 16, 2025

Can you try adding vite-vue-jsx and the tsx extension in the vite vue components config?

https://github.com/unplugin/unplugin-vue-components/blob/main/src/types.ts#L89

@atox996
Copy link
Author

atox996 commented Apr 17, 2025

Can you try adding vite-vue-jsx and the tsx extension in the vite vue components config?

https://github.com/unplugin/unplugin-vue-components/blob/main/src/types.ts#L89

Yes, I have already done so, but it only recognizes file extensions in the dirs directory, and the resulting components can only be used in the vue module, which makes it impossible to directly use these components in the tsx file

declare module 'vue' {
  export interface GlobalComponents {
    TForm: typeof import('tdesign-vue-next')['Form'];
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants