Skip to content
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

'XXIcon' cannot be used as a JSX component (Vue) #607

Closed
TiBianMod opened this issue Feb 20, 2022 · 1 comment · Fixed by #608
Closed

'XXIcon' cannot be used as a JSX component (Vue) #607

TiBianMod opened this issue Feb 20, 2022 · 1 comment · Fixed by #608
Assignees

Comments

@TiBianMod
Copy link
Contributor

TiBianMod commented Feb 20, 2022

If you create a TSX Component and try to use any icon you will receive a nice TypeScript error...

TS2786: 'BeakerIcon' cannot be used as a JSX component.  
Its return type 'VNodeChild' is not a valid JSX element.
Type 'undefined' is not assignable to type 'Element | null'.

CleanShot 2022-02-20 at 01 55 39

The issue is that icons are declared as RenderFunction and the return type of the RenderFunction is VNodeChild and VNodeChild is not a valid JSX element.

// From runtime-core.d.ts
export declare type RenderFunction = () => VNodeChild;

I know we have already two pull request (#322 and #549) about this issue, but with tsx files I had the same issue allways !!!

Let's use the generated code from the Beaker Icon to test the types from the two pull requests (#322 and #549)

Let's test RenderFunction type

you can see the type is not compatible.

CleanShot 2022-02-20 at 03 09 58

Let's test DefineComponent type

you can see again the type is not compatible.

CleanShot 2022-02-20 at 03 29 20

Let's test FunctionalComponent type

and you can see the type is compatible and vue-tsc reports no errors.

CleanShot 2022-02-20 at 03 25 52
CleanShot 2022-02-20 at 03 33 17

I'm preparing a pull request to solve this issue.

@TiBianMod
Copy link
Contributor Author

@bradlc can you have a look on the issue please.

Simply create a MyComponent.tsx file and you will see the error immediately.

import { BeakerIcon } from '@heroicons/vue/solid'

export default function MyComponent() {
    return <BeakerIcon />
}

@RobinMalfait RobinMalfait self-assigned this Feb 24, 2022
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

Successfully merging a pull request may close this issue.

2 participants