-
Notifications
You must be signed in to change notification settings - Fork 30.5k
[react] Add JSX namespace to React namespace #64464
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
Changes from all commits
bc03310
fd88acb
5469297
b80d360
846ea55
9950cf2
0e108c3
44e4b24
a504ae0
be4c11e
33aebca
90e99c9
4df2ed1
4e1c582
649ab64
3dea057
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,7 +175,8 @@ const Box = () => <box style={{ fg: "blue" }} />; | |
| const BlessedBox = () => <blessed-box style={{ fg: "blue" }} />; | ||
| const FF: React.FC<ReactBlessed.BlessedIntrinsicElements["box"]> = props => <box {...props} />; | ||
|
|
||
| // @ts-expect-error | ||
| // Undesired. Should error but we can only augment intrinsic elements. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as in - you can't remove a declared existing intrinsic element? that makes sense but I wonder if react-blessed types couldnt be juggled to allow better types through
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is on our side since we mix in DOM related things into Once that's done, It would be really great if could separate
I think so because declaration merging is only additive. We could potentially create an API with which you could essentially remove it but it would be specific to React and feel pretty hacky. |
||
| // Should not typecheck once `@types/react` moves DOM intrinsics to `react-dom`. | ||
| const Div = () => <div />; | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1382,6 +1382,9 @@ declare namespace React { | |
| interface SVGProps<T> extends SVGAttributes<T>, ClassAttributes<T> { | ||
| } | ||
|
|
||
| interface SVGLineElementAttributes<T> extends SVGProps<T> {} | ||
| interface SVGTextElementAttributes<T> extends SVGProps<T> {} | ||
|
|
||
| interface DOMAttributes<T> { | ||
| children?: ReactNode | undefined; | ||
| dangerouslySetInnerHTML?: { | ||
|
|
@@ -3099,6 +3102,19 @@ declare namespace React { | |
| */ | ||
| componentStack: string; | ||
| } | ||
|
|
||
| namespace JSX { | ||
| interface Element extends GlobalJSXElement {} | ||
| interface ElementClass extends GlobalJSXElementClass {} | ||
| interface ElementAttributesProperty extends GlobalJSXElementAttributesProperty {} | ||
| interface ElementChildrenAttribute extends GlobalJSXElementChildrenAttribute {} | ||
|
|
||
| type LibraryManagedAttributes<C, P> = GlobalJSXLibraryManagedAttributes<C, P>; | ||
|
|
||
| interface IntrinsicAttributes extends GlobalJSXIntrinsicAttributes {} | ||
| interface IntrinsicClassAttributes<T> extends GlobalJSXIntrinsicClassAttributes<T> {} | ||
| interface IntrinsicElements extends GlobalJSXIntrinsicElements {} | ||
| } | ||
| } | ||
|
|
||
| // naked 'any' type in a conditional type will short circuit and union both the then/else branches | ||
|
|
@@ -3146,6 +3162,9 @@ type ReactManagedAttributes<C, P> = C extends { propTypes: infer T; defaultProps | |
| : P; | ||
|
|
||
| declare global { | ||
| /** | ||
| * @deprecated Use `React.JSX` instead of the global `JSX` namespace. | ||
| */ | ||
| namespace JSX { | ||
| interface Element extends React.ReactElement<any, any> { } | ||
| interface ElementClass extends React.Component<any> { | ||
|
|
@@ -3326,7 +3345,7 @@ declare global { | |
| foreignObject: React.SVGProps<SVGForeignObjectElement>; | ||
| g: React.SVGProps<SVGGElement>; | ||
| image: React.SVGProps<SVGImageElement>; | ||
| line: React.SVGProps<SVGLineElement>; | ||
| line: React.SVGLineElementAttributes<SVGLineElement>; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q: why this new interface was added? I certainly don't mind it - I'm just curious
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So that |
||
| linearGradient: React.SVGProps<SVGLinearGradientElement>; | ||
| marker: React.SVGProps<SVGMarkerElement>; | ||
| mask: React.SVGProps<SVGMaskElement>; | ||
|
|
@@ -3341,11 +3360,26 @@ declare global { | |
| stop: React.SVGProps<SVGStopElement>; | ||
| switch: React.SVGProps<SVGSwitchElement>; | ||
| symbol: React.SVGProps<SVGSymbolElement>; | ||
| text: React.SVGProps<SVGTextElement>; | ||
| text: React.SVGTextElementAttributes<SVGTextElement>; | ||
| textPath: React.SVGProps<SVGTextPathElement>; | ||
| tspan: React.SVGProps<SVGTSpanElement>; | ||
| use: React.SVGProps<SVGUseElement>; | ||
| view: React.SVGProps<SVGViewElement>; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // React.JSX needs to point to global.JSX to keep global module augmentations intact. | ||
| // But we can't access global.JSX so we need to create these aliases instead. | ||
| // Once the global JSX namespace will be removed we replace React.JSX with the contents of global.JSX | ||
| interface GlobalJSXElement extends JSX.Element {} | ||
| interface GlobalJSXElementClass extends JSX.ElementClass {} | ||
| interface GlobalJSXElementAttributesProperty extends JSX.ElementAttributesProperty {} | ||
| interface GlobalJSXElementChildrenAttribute extends JSX.ElementChildrenAttribute {} | ||
|
|
||
| type GlobalJSXLibraryManagedAttributes<C, P> = JSX.LibraryManagedAttributes<C, P>; | ||
|
|
||
| interface GlobalJSXIntrinsicAttributes extends JSX.IntrinsicAttributes {} | ||
| interface GlobalJSXIntrinsicClassAttributes<T> extends JSX.IntrinsicClassAttributes<T> {} | ||
|
|
||
| interface GlobalJSXIntrinsicElements extends JSX.IntrinsicElements {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,12 @@ | ||
| // Expose `JSX` namespace in `global` namespace | ||
| import './'; | ||
| import * as React from './'; | ||
|
|
||
| export namespace JSX { | ||
| interface Element extends React.JSX.Element {} | ||
| interface ElementClass extends React.JSX.ElementClass {} | ||
| interface ElementAttributesProperty extends React.JSX.ElementAttributesProperty {} | ||
| interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {} | ||
| type LibraryManagedAttributes<C, P> = React.JSX.LibraryManagedAttributes<C, P>; | ||
| interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {} | ||
| interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {} | ||
| interface IntrinsicElements extends React.JSX.IntrinsicElements {} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,12 @@ | ||
| // Expose `JSX` namespace in `global` namespace | ||
| import './'; | ||
| import * as React from './'; | ||
|
|
||
| export namespace JSX { | ||
| interface Element extends React.JSX.Element {} | ||
| interface ElementClass extends React.JSX.ElementClass {} | ||
| interface ElementAttributesProperty extends React.JSX.ElementAttributesProperty {} | ||
| interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {} | ||
| type LibraryManagedAttributes<C, P> = React.JSX.LibraryManagedAttributes<C, P>; | ||
| interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {} | ||
| interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {} | ||
| interface IntrinsicElements extends React.JSX.IntrinsicElements {} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,12 @@ | ||
| // Expose `JSX` namespace in `global` namespace | ||
| import './'; | ||
| import * as React from './'; | ||
|
|
||
| export namespace JSX { | ||
| interface Element extends React.JSX.Element {} | ||
| interface ElementClass extends React.JSX.ElementClass {} | ||
| interface ElementAttributesProperty extends React.JSX.ElementAttributesProperty {} | ||
| interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {} | ||
| type LibraryManagedAttributes<C, P> = React.JSX.LibraryManagedAttributes<C, P>; | ||
| interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {} | ||
| interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {} | ||
| interface IntrinsicElements extends React.JSX.IntrinsicElements {} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,12 @@ | ||
| // Expose `JSX` namespace in `global` namespace | ||
| import './'; | ||
| import * as React from './'; | ||
|
|
||
| export namespace JSX { | ||
| interface Element extends React.JSX.Element {} | ||
| interface ElementClass extends React.JSX.ElementClass {} | ||
| interface ElementAttributesProperty extends React.JSX.ElementAttributesProperty {} | ||
| interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {} | ||
| type LibraryManagedAttributes<C, P> = React.JSX.LibraryManagedAttributes<C, P>; | ||
| interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {} | ||
| interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {} | ||
| interface IntrinsicElements extends React.JSX.IntrinsicElements {} | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
react-blessed relied on a scoped namespace not existing. It wasn't actually using module augmentation. The changes are required to make it work with actual module augmentation since React now has a scoped JSX namespace