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

JSX type errors on React Bootstrap 2.x & Preact 10.x #4425

Open
1 task done
TechQuery opened this issue Jun 27, 2024 · 6 comments
Open
1 task done

JSX type errors on React Bootstrap 2.x & Preact 10.x #4425

TechQuery opened this issue Jun 27, 2024 · 6 comments
Labels

Comments

@TechQuery
Copy link

TechQuery commented Jun 27, 2024

  • Check if updating to the latest Preact version resolves the issue

Describe the bug

Every React Bootstrap component with Preact has a similar error as shown below:

'Container' cannot be used as a JSX component.
  Its type 'BsPrefixRefForwardingComponent<"div", ContainerProps>' is not a valid JSX element type.
    Type 'BsPrefixRefForwardingComponent<"div", ContainerProps>' is not assignable to type 'FunctionComponent<any>'.
      Type 'ComponentChild' is not assignable to type 'VNode<any>'.
        Type 'string' is not assignable to type 'VNode<any>'.ts(2786)

To Reproduce

Steps to reproduce the behavior

  1. git clone https://github.com/idea2app/React-MobX-Bootstrap-ts
  2. npm i
  3. npx tsc --noEmit

Expected behavior

No type errors as React does.

@rschristian
Copy link
Member

Please provide a minimal reproduction, it's not fair to ask maintainers to browser through a full project.

@TechQuery
Copy link
Author

TechQuery commented Jun 27, 2024

Please provide a minimal reproduction, it's not fair to ask maintainers to browser through a full project.

@rschristian That repository is not a full project, it's just a scaffold with some simple example pages, but almost every page & component has the same type errors...

@rschristian
Copy link
Member

rschristian commented Jun 27, 2024

Anything more than a few files in src is non-minimal. Please clear it out to the minimum that is required to demonstrate the issue.

This is the example StackBlitz we provide in the bug template, which is just about ideal for a web reproduction. For type errors you could certainly go even more minimal.

@TechQuery
Copy link
Author

This is the example StackBlitz we provide in the bug template, which is just about ideal for a web reproduction.

Thanks, but Parcel 2.x is my real bundler, not Vite: https://codesandbox.io/p/devbox/preact-react-bootstrap-llqsv9?file=%2Fsrc%2Findex.tsx%3A5%2C14

@rschristian
Copy link
Member

Build tooling isn't likely to matter in a types issue, but regardless, it's just an example of scope that's appropriate. But thanks, the minimal repro does help.

Looks like we'll need to widen FunctionComponent to return ComponentChild as React does, but that seems to cause havoc in our tests:

-	(props: RenderableProps<P>, context?: any): VNode<any> | null; 
+	(props: RenderableProps<P>, context?: any): ComponentChild;

(props: RenderableProps<P>, context?: any): VNode<any> | null;

Will need to play around with this for a bit.

@TechQuery
Copy link
Author

TechQuery commented Jun 28, 2024

Looks like we'll need to widen FunctionComponent to return ComponentChild as React does, but that seems to cause havoc in our tests:

-	(props: RenderableProps<P>, context?: any): VNode<any> | null; 
+	(props: RenderableProps<P>, context?: any): ComponentChild;

(props: RenderableProps<P>, context?: any): VNode<any> | null;

My Web components engine may have the same issue😂

https://github.com/EasyWebApp/WebCell/blob/28b30a187fc2672cfaa145707d0df2014b630a1d/source/decorator.ts#L22

(PReact's JSX type definition is my major reference instead of confusing @types/react, I have a big thank to you guys.)

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

No branches or pull requests

2 participants