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

React-compat type definitions for preact/compat? #2222

Closed
BasixKOR opened this issue Jan 3, 2020 · 8 comments
Closed

React-compat type definitions for preact/compat? #2222

BasixKOR opened this issue Jan 3, 2020 · 8 comments
Labels

Comments

@BasixKOR
Copy link

BasixKOR commented Jan 3, 2020

I don't think this would be an easy task, but some libraries (i.e. linaria/react)'s type definitions are based on the type definitions of @types/react, which isn't compatible with Preact's type definitions. I tried aliasing TypeScript module resolution via tsconfig but it didn't give me the result I expected.

Could we have a compatible type definitions on preact/compat? Any solutions for solving this type issue is also welcome.

@ForsakenHarmony
Copy link
Member

See #2150 (comment)

It might help you

@BasixKOR
Copy link
Author

BasixKOR commented Jan 9, 2020

Cool! But why we don't ship them by default?

@JoviDeCroock
Copy link
Member

We do you can follow the package.json to find them so importing from preact/compat also imports from the typings file.

@BasixKOR
Copy link
Author

I mean, we could improve even further by aliasing some of React types. Just a simple addition like #2150 (comment) could remove a lot of type incompatibilities in React libraries.

I'm willing to file a PR if you don't mind.

@bvella
Copy link

bvella commented Feb 11, 2020

Added a pr that may solve some of these issues #2329

@ForsakenHarmony
Copy link
Member

Can you alias them directly when you have compatible typings?

@matthias-ccri
Copy link

Just a note, when a type is missing, typescript replaces it with any, which results in missing type inference and error checking in JSX.

This issue has simmered down probably because a workaround exists, but the posted workaround is not comprehensive, so people will adapt it as needed, resulting in everyone having a slightly different version, which creates some fragmentation.

I've been impressed with the comprehensiveness of @types/react, and I think preact needs to align with it or else it gives the appearance that preact has worse support for types ("this library's types worked in react but they don't work in preact"). Though keeping track of @types/react is an added burden on the preact project.

@rschristian
Copy link
Member

Our docs now instruct to alias react & react/dom types to preact/compat: https://preactjs.com/guide/v10/getting-started#aliasing-in-typescript

If you run into any incompatibilities/missing types, please open an issue. We'd be happy to add them.

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

6 participants