preact icon indicating copy to clipboard operation
preact copied to clipboard

Improve react typescript compatibility

Open bvella opened this issue 4 years ago • 10 comments

bvella avatar Feb 11 '20 11:02 bvella

Fixed #1930

bvella avatar Feb 11 '20 11:02 bvella

For clarity, I am trying to get an existing react project working with preact. I encountered a number of typescript incompatibilities as described in #1930 and attempted to fix them with the proposed changes.

I added the following in my tsconfig.json:

{
  "compilerOptions": {
    ...
    "paths": {
      "react": ["node_modules/preact/compat/"],
      "react-dom": ["node_modules/preact/compat/"]
    }
  }
}

And in package.json applied a browserify global transform using aliasify to alias react and react-dom to preact/compat.

bvella avatar Feb 11 '20 11:02 bvella

Coverage Status

Coverage remained the same at 99.798% when pulling 770ac2092568f9fffeb349c9e9c090987320fffd on bvella:improve-react-ts-compat into 020d5e599b8b84745932f092a835f494b1dd2261 on preactjs:master.

coveralls avatar Feb 11 '20 11:02 coveralls

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

bvella avatar Feb 12 '20 08:02 bvella

I know it's been a while, there are some more types missing in #2414 if you want to add those

ForsakenHarmony avatar Mar 29 '20 00:03 ForsakenHarmony

Any chance this could be merged? 👼

brookback avatar Jun 03 '20 07:06 brookback

When using @apollo/client

ERROR in ./node_modules/@apollo/client/react/context/ApolloConsumer.d.ts(4,55):
TS2694: Namespace 'React' has no exported member 'ReactChild'.

I wasn't using this branch though, but I guess you need to add ReactChild too ?

toniopelo avatar Jun 18 '20 09:06 toniopelo

@bvella could you update this branch with the base branch so it can be re-approved and then released?

dgreene1 avatar Jul 20 '20 17:07 dgreene1

Any update on this? Is there a complete workaround with all the changes needed to perform to a Preact project to be able to use typed React libraries in it until it merged?

evenfrost avatar Feb 11 '21 10:02 evenfrost

I would like to contribute to this effort.. I'm not sure how to do it besides creating a separate PR. Is that ok?

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