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

move JSX namespace into preact one #1448

Merged
merged 3 commits into from
Apr 4, 2019

Conversation

just-boris
Copy link
Contributor

closes #1036. Still requires some work, but open for initial feedback.

This change fixes issues when preact is used together with @types/react in dependencies. Conflicting JSX namespace definitions confuse typescript. Here is a demo project, where I tested integration with react typings: https://github.com/just-boris/preact-mix

Implementing the approach described in the related typescript issue: microsoft/TypeScript#23762 (comment)

Not yet ready to merge, because it requires the fix in typescript to be released microsoft/TypeScript#30160.

@coveralls
Copy link

coveralls commented Mar 24, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling c15e9d1 on just-boris:master into a032782 on developit:master.

@developit
Copy link
Member

@just-boris It seems like it might be a little while before we could release this since it breaks TS <3.4, right?

@marvinhagemeister
Copy link
Member

It's not a good sample size but from my experience TS users don't take long to upgrade.

@marvinhagemeister
Copy link
Member

FYI: TypeScript 3.4 was released just a few days ago 🎉

@just-boris
Copy link
Contributor Author

It seems like it might be a little while before we could release this since it breaks TS

I will do extra testing to see how exactly it breaks older TS and if there are any possible workarounds (for example, various options in tsconfig.json).

It's not a good sample size but from my experience TS users don't take long to upgrade.

Typescript minor releases contain breaking changes, so users are advised to lock version in dependencies. So, onboarding on the new version would require an effort from developers.

So, it is worth to consider possible impact of shipping this change. I will check if this change fixes more things than breaks and update the PR.

@just-boris
Copy link
Contributor Author

Updated the PR, added an extra test for this scenario.

I have also checked how this works under different versions of Typescript. The above-mentioned error (microsoft/TypeScript#30160) is happening only when you are using Preact and JSX directly. But if you have preact is a transitive dependency and you do not use it directly, you will be fine.

That said, I believe this change brings more benefits than opens potential issues. Moreover, as soon as change gets released as an alpha version, it should be fine to require the newest typescript to make it work.

unknownProperty: string
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This snippet simulates what @types/react does. Will you be interested in having the real React typings as a dev-dependency instead of this mock?

@jeremy-coleman
Copy link
Contributor

I recently ran into a case where some types are actually different, onDoubleClick in react is onDblClick in preact, if i was using react types i would have never found the cause

@JoviDeCroock
Copy link
Member

I recently ran into a case where some types are actually different, onDoubleClick in react is onDblClick in preact, if i was using react types i would have never found the cause

Yes this is normalized in preact/compat but in preact the native events are used.

@just-boris
Copy link
Contributor Author

@marvinhagemeister @developit do you need anything else from me to get this PR merged?

@marvinhagemeister
Copy link
Member

@just-boris The PR is awesome and will be merged soon 👍 We were just more focused on getting alpha 3 out first 🙂

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

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

Wohoo! This will make interop with 3rd-party react libs a lot easier! Super excited about this 👍 🎉

@marvinhagemeister marvinhagemeister merged commit 0246cd8 into preactjs:master Apr 4, 2019
rymndhng added a commit to rymndhng/DefinitelyTyped that referenced this pull request Jun 5, 2019
When using both `preact` and `react` in typescript projects, the type checker gets conflicting type definitions because both projects declare global JSX definitions. Typescript since 2.8 has recommended libraries to internally namespace `JSX` to avoid conflicting definitions. See factory functions: https://www.typescriptlang.org/docs/handbook/jsx.html#factory-functions.

Preact 10.x already switched to internally namespaced JSX. See preactjs/preact#1448
@tbremer tbremer mentioned this pull request Mar 23, 2021
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TS: Move JSX namespace to preact one
6 participants