preact icon indicating copy to clipboard operation
preact copied to clipboard

React-compat type definitions for `preact/compat`?

Open BasixKOR opened this issue 4 years ago • 7 comments

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.

BasixKOR avatar Jan 03 '20 09:01 BasixKOR

See https://github.com/preactjs/preact/issues/2150#issuecomment-558622551

It might help you

ForsakenHarmony avatar Jan 09 '20 02:01 ForsakenHarmony

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

BasixKOR avatar Jan 09 '20 14:01 BasixKOR

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

JoviDeCroock avatar Jan 09 '20 14:01 JoviDeCroock

I mean, we could improve even further by aliasing some of React types. Just a simple addition like https://github.com/preactjs/preact/issues/2150#issuecomment-558622551 could remove a lot of type incompatibilities in React libraries.

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

BasixKOR avatar Jan 10 '20 02:01 BasixKOR

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

bvella avatar Feb 11 '20 11:02 bvella

Can you alias them directly when you have compatible typings?

ForsakenHarmony avatar Feb 13 '20 13:02 ForsakenHarmony

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.

matthias-ccri avatar Apr 30 '21 15:04 matthias-ccri