-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improved compatibility with the upcoming @types/react for React 19
#3206
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8ab8085
Bump @react/types
DiegoAndai 054a5cb
Replace JSX type with React.JSX
DiegoAndai 2b38a93
Changeset
DiegoAndai be051c0
Update lock file
DiegoAndai eb258fa
Adapt to ast array elements posibly being null
DiegoAndai ee537c1
Update .changeset/curly-houses-jump.md
Andarist 4af435e
simplify one thing
Andarist aa7c31b
revert unrelated change
Andarist 204b695
pin types/react
Andarist 245cd55
slim down yarn.lock changes
Andarist 5ef7366
dedupe types/react
Andarist d06fb10
pick the correct JSX namespace based on version
Andarist a4d896f
Update .changeset/curly-houses-jump.md
Andarist 33e41a8
allow ts-ignores as we need them
Andarist b9b2b18
patch dtslint
Andarist bdbc33b
suppress extra rules in styled pkg
Andarist 0505dac
fix thing
Andarist 8c602ad
Remove everything besides ReactJSXIntrinsicElements from packages/sty…
emmatown 7b6928e
Merge branch 'main' into react-18.2-types
emmatown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@emotion/styled': patch | ||
| '@emotion/react': patch | ||
| --- | ||
|
|
||
| Replace global JSX type with React.JSX | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,25 +2,81 @@ import 'react' | |
| import { Interpolation } from '@emotion/serialize' | ||
| import { Theme } from '@emotion/react' | ||
|
|
||
| type IsPreReact19 = 2 extends Parameters<React.FunctionComponent<any>>['length'] | ||
| ? true | ||
| : false | ||
|
|
||
| type WithConditionalCSSProp<P> = 'className' extends keyof P | ||
| ? string extends P['className' & keyof P] | ||
| ? { css?: Interpolation<Theme> } | ||
| : {} | ||
| : {} | ||
|
|
||
| // unpack all here to avoid infinite self-referencing when defining our own JSX namespace | ||
| type ReactJSXElement = JSX.Element | ||
| type ReactJSXElementClass = JSX.ElementClass | ||
| type ReactJSXElementAttributesProperty = JSX.ElementAttributesProperty | ||
| type ReactJSXElementChildrenAttribute = JSX.ElementChildrenAttribute | ||
| type ReactJSXLibraryManagedAttributes<C, P> = JSX.LibraryManagedAttributes<C, P> | ||
| type ReactJSXIntrinsicAttributes = JSX.IntrinsicAttributes | ||
| type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T> | ||
| type ReactJSXIntrinsicElements = JSX.IntrinsicElements | ||
|
|
||
| // based on the code from @types/[email protected] | ||
| // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/3197efc097d522c4bf02b94e1a0766d007d6cdeb/types/react/index.d.ts#LL3204C13-L3204C13 | ||
| type ReactJSXElementType = string | React.JSXElementConstructor<any> | ||
| // unpack all here to avoid infinite self-referencing when defining our own JSX namespace for the pre-React 19 case | ||
| type ReactJSXElement = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.Element | ||
| : /** @ts-ignore */ | ||
| React.JSX.Element | ||
| type ReactJSXElementClass = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.ElementClass | ||
| : /** @ts-ignore */ | ||
| React.JSX.ElementClass | ||
| type ReactJSXElementAttributesProperty = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.ElementAttributesProperty | ||
| : /** @ts-ignore */ | ||
| React.JSX.ElementAttributesProperty | ||
| type ReactJSXElementChildrenAttribute = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.ElementChildrenAttribute | ||
| : /** @ts-ignore */ | ||
| React.JSX.ElementChildrenAttribute | ||
| type ReactJSXLibraryManagedAttributes<C, P> = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.LibraryManagedAttributes<C, P> | ||
| : /** @ts-ignore */ | ||
| React.JSX.LibraryManagedAttributes<C, P> | ||
| type ReactJSXIntrinsicAttributes = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.IntrinsicAttributes | ||
| : /** @ts-ignore */ | ||
| React.JSX.IntrinsicAttributes | ||
| type ReactJSXIntrinsicClassAttributes<T> = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.IntrinsicClassAttributes<T> | ||
| : /** @ts-ignore */ | ||
| React.JSX.IntrinsicClassAttributes<T> | ||
| type ReactJSXIntrinsicElements = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.IntrinsicElements | ||
| : /** @ts-ignore */ | ||
| React.JSX.IntrinsicElements | ||
|
|
||
| type ReactJSXElementType = true extends IsPreReact19 | ||
| ? // based on the code from @types/[email protected] | ||
| // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/3197efc097d522c4bf02b94e1a0766d007d6cdeb/types/react/index.d.ts#LL3204C13-L3204C13 | ||
| string | React.JSXElementConstructor<any> | ||
| : /** @ts-ignore */ | ||
| React.JSX.ElementType | ||
|
|
||
| export namespace ReactJSX { | ||
| type ElementType = ReactJSXElementType | ||
| interface Element extends ReactJSXElement {} | ||
| interface ElementClass extends ReactJSXElementClass {} | ||
| interface ElementAttributesProperty | ||
| extends ReactJSXElementAttributesProperty {} | ||
| interface ElementChildrenAttribute extends ReactJSXElementChildrenAttribute {} | ||
|
|
||
| type LibraryManagedAttributes<C, P> = ReactJSXLibraryManagedAttributes<C, P> | ||
|
|
||
| interface IntrinsicAttributes extends ReactJSXIntrinsicAttributes {} | ||
| interface IntrinsicClassAttributes<T> | ||
| extends ReactJSXIntrinsicClassAttributes<T> {} | ||
|
|
||
| type IntrinsicElements = ReactJSXIntrinsicElements | ||
| } | ||
|
|
||
| export namespace EmotionJSX { | ||
| type ElementType = ReactJSXElementType | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // this is basically a slimmed down copy of https://github.com/emotion-js/emotion/blob/main/packages/react/types/jsx-namespace.d.ts | ||
| // it helps to avoid issues when combining newer `@emotion/styled` and older `@emotion/react` versions | ||
| // in such setup, ReactJSX namespace won't exist in `@emotion/react` and that would lead to errors | ||
| import 'react' | ||
|
|
||
| type IsPreReact19 = 2 extends Parameters<React.FunctionComponent<any>>['length'] | ||
| ? true | ||
| : false | ||
|
|
||
| // unpack all here to avoid infinite self-referencing when defining our own JSX namespace for the pre-React 19 case | ||
| type ReactJSXElement = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.Element | ||
| : /** @ts-ignore */ | ||
| React.JSX.Element | ||
| type ReactJSXElementClass = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.ElementClass | ||
| : /** @ts-ignore */ | ||
| React.JSX.ElementClass | ||
| type ReactJSXElementAttributesProperty = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.ElementAttributesProperty | ||
| : /** @ts-ignore */ | ||
| React.JSX.ElementAttributesProperty | ||
| type ReactJSXElementChildrenAttribute = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.ElementChildrenAttribute | ||
| : /** @ts-ignore */ | ||
| React.JSX.ElementChildrenAttribute | ||
| type ReactJSXLibraryManagedAttributes<C, P> = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.LibraryManagedAttributes<C, P> | ||
| : /** @ts-ignore */ | ||
| React.JSX.LibraryManagedAttributes<C, P> | ||
| type ReactJSXIntrinsicAttributes = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.IntrinsicAttributes | ||
| : /** @ts-ignore */ | ||
| React.JSX.IntrinsicAttributes | ||
| type ReactJSXIntrinsicClassAttributes<T> = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.IntrinsicClassAttributes<T> | ||
| : /** @ts-ignore */ | ||
| React.JSX.IntrinsicClassAttributes<T> | ||
| type ReactJSXIntrinsicElements = true extends IsPreReact19 | ||
| ? /** @ts-ignore */ | ||
| JSX.IntrinsicElements | ||
| : /** @ts-ignore */ | ||
| React.JSX.IntrinsicElements | ||
|
|
||
| type ReactJSXElementType = true extends IsPreReact19 | ||
| ? // based on the code from @types/[email protected] | ||
| // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/3197efc097d522c4bf02b94e1a0766d007d6cdeb/types/react/index.d.ts#LL3204C13-L3204C13 | ||
| string | React.JSXElementConstructor<any> | ||
| : /** @ts-ignore */ | ||
| React.JSX.ElementType | ||
|
|
||
| export namespace ReactJSX { | ||
| type ElementType = ReactJSXElementType | ||
| interface Element extends ReactJSXElement {} | ||
| interface ElementClass extends ReactJSXElementClass {} | ||
| interface ElementAttributesProperty | ||
| extends ReactJSXElementAttributesProperty {} | ||
| interface ElementChildrenAttribute extends ReactJSXElementChildrenAttribute {} | ||
|
|
||
| type LibraryManagedAttributes<C, P> = ReactJSXLibraryManagedAttributes<C, P> | ||
|
|
||
| interface IntrinsicAttributes extends ReactJSXIntrinsicAttributes {} | ||
| interface IntrinsicClassAttributes<T> | ||
| extends ReactJSXIntrinsicClassAttributes<T> {} | ||
|
|
||
| type IntrinsicElements = ReactJSXIntrinsicElements | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.