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

Typescript - Components created via JSX "forget"/erase their type #2121

Closed
transbitch opened this issue Apr 8, 2024 · 3 comments
Closed
Labels
typescript relating to typescript or types

Comments

@transbitch
Copy link

Describe the bug

When a component is created via JSX, it "forgets"/erases the type of the underlying component and assumes that it's simply a JSX.Element. This is an incorrect assumption when the type that the function is some intersection, e.g. a component that returns JSX.Element & FooTy (see stackblitz).

Your Example Website or App

https://stackblitz.com/edit/solidjs-templates-dch5bb?file=src%2FApp.tsx

Steps to Reproduce the Bug or Issue

const FooSymbol = Symbol('Foo');

type FooTy = {
  __foo: typeof FooSymbol;
};

// Returns JSX.Element & FooTy (hover over `Foo`)
const Foo = () => {
  return (<>Foo</>) as JSX.Element & FooTy;
};

// Returns JSX Element!!! (not JSX.Element & FooTy as desired)
const App = () => {
  return <Foo />;
};

Expected behavior

<Foo /> should have the same type as Foo().

Screenshots or Videos

No response

Platform

  • OS: Windows
  • Browser: Firefox
  • Version: 1.7.6

Additional context

No response

@ryansolid
Copy link
Member

I'm pretty sure this is a TypeScript-ism that we can't change. It is just how JSX in typescript work. But I'd love to shown otherwise.

@ryansolid ryansolid added the typescript relating to typescript or types label Apr 8, 2024
@transbitch
Copy link
Author

transbitch commented Apr 10, 2024

I'm pretty sure this is a TypeScript-ism that we can't change. It is just how JSX in typescript work. But I'd love to shown otherwise.

You're totally right, I just looked it up, it's an issue with typescript. React hasn't figured it out either.. Closing as this is blocked by a TS issue open since 2017.

@transbitch transbitch closed this as not planned Won't fix, can't repro, duplicate, stale Apr 10, 2024
@ryansolid
Copy link
Member

Yeah I think we could benefit from this even more than React given we can have real DOM element types. Anyway, all good. This issue can be a reference for the next person who comes along.

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

No branches or pull requests

2 participants