Skip to content

Improve react typescript compatibility - #2329

Open
bvella wants to merge 10 commits into
preactjs:mainfrom
bvella:improve-react-ts-compat
Open

Improve react typescript compatibility#2329
bvella wants to merge 10 commits into
preactjs:mainfrom
bvella:improve-react-ts-compat

Conversation

@bvella

@bvella bvella commented Feb 11, 2020

Copy link
Copy Markdown

No description provided.

@bvella

bvella commented Feb 11, 2020

Copy link
Copy Markdown
Author

Fixed #1930

@bvella

bvella commented Feb 11, 2020

Copy link
Copy Markdown
Author

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

coveralls commented Feb 11, 2020

Copy link
Copy Markdown

Coverage Status

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

@bvella

bvella commented Feb 12, 2020

Copy link
Copy Markdown
Author

Incorporated #2150 (comment)

@ForsakenHarmony

Copy link
Copy Markdown
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
Copy Markdown

Any chance this could be merged? 👼

Comment thread compat/src/jsx.d.ts
import { JSXInternal } from '../../src/jsx';

export = JSXInternal;
export as namespace JSX; No newline at end of file

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown

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

@evenfrost

Copy link
Copy Markdown

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
Copy Markdown

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.

8 participants