preact
preact copied to clipboard
React-compat type definitions for `preact/compat`?
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.
See https://github.com/preactjs/preact/issues/2150#issuecomment-558622551
It might help you
Cool! But why we don't ship them by default?
We do you can follow the package.json
to find them so importing from preact/compat
also imports from the typings file.
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.
Added a pr that may solve some of these issues #2329
Can you alias them directly when you have compatible typings?
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.