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

Improve react typescript compatibility #2329

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

bvella
Copy link

@bvella bvella commented Feb 11, 2020

No description provided.

@bvella
Copy link
Author

bvella commented Feb 11, 2020

Fixed #1930

@bvella
Copy link
Author

bvella commented Feb 11, 2020

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.

@coveralls
Copy link

coveralls commented Feb 11, 2020

Coverage Status

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

@bvella
Copy link
Author

bvella commented Feb 12, 2020

Incorporated #2150 (comment)

@ForsakenHarmony
Copy link
Member

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

@brookback
Copy link

Any chance this could be merged? 👼

import { JSXInternal } from '../../src/jsx';

export = JSXInternal;
export as namespace JSX;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this broke typescript before

preactjs/preact-cli#1030

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what way? I skimmed through the referenced issue but did not understand how this breaks typescript. This file declares the JSX namespace, without which, typescript does not process jsx. This is also the same way react itself exports the JSX namespace

@toniopelo
Copy link

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 ?

@dgreene1
Copy link

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

@evenfrost
Copy link

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?

@matthias-ccri
Copy link

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

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

Successfully merging this pull request may close these issues.

None yet

8 participants