-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Fix #15463: use intersection types to emulate spread in generic react components #15851
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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,40 @@ | ||
//// [file.tsx] | ||
import React = require('react'); | ||
|
||
export function makeP<P>(Ctor: React.ComponentClass<P>): React.ComponentClass<P> { | ||
return class extends React.PureComponent<P, void> { | ||
public render(): JSX.Element { | ||
return ( | ||
<Ctor {...this.props } /> | ||
); | ||
} | ||
}; | ||
} | ||
|
||
//// [file.jsx] | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
exports.__esModule = true; | ||
var React = require("react"); | ||
function makeP(Ctor) { | ||
return (function (_super) { | ||
__extends(class_1, _super); | ||
function class_1() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
class_1.prototype.render = function () { | ||
return (<Ctor {...this.props}/>); | ||
}; | ||
return class_1; | ||
}(React.PureComponent)); | ||
} | ||
exports.makeP = makeP; |
37 changes: 37 additions & 0 deletions
37
tests/baselines/reference/tsxGenericAttributesType9.symbols
This file contains 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,37 @@ | ||
=== tests/cases/conformance/jsx/file.tsx === | ||
import React = require('react'); | ||
>React : Symbol(React, Decl(file.tsx, 0, 0)) | ||
|
||
export function makeP<P>(Ctor: React.ComponentClass<P>): React.ComponentClass<P> { | ||
>makeP : Symbol(makeP, Decl(file.tsx, 0, 32)) | ||
>P : Symbol(P, Decl(file.tsx, 2, 22)) | ||
>Ctor : Symbol(Ctor, Decl(file.tsx, 2, 25)) | ||
>React : Symbol(React, Decl(file.tsx, 0, 0)) | ||
>ComponentClass : Symbol(React.ComponentClass, Decl(react.d.ts, 204, 5)) | ||
>P : Symbol(P, Decl(file.tsx, 2, 22)) | ||
>React : Symbol(React, Decl(file.tsx, 0, 0)) | ||
>ComponentClass : Symbol(React.ComponentClass, Decl(react.d.ts, 204, 5)) | ||
>P : Symbol(P, Decl(file.tsx, 2, 22)) | ||
|
||
return class extends React.PureComponent<P, void> { | ||
>React.PureComponent : Symbol(React.PureComponent, Decl(react.d.ts, 179, 5)) | ||
>React : Symbol(React, Decl(file.tsx, 0, 0)) | ||
>PureComponent : Symbol(React.PureComponent, Decl(react.d.ts, 179, 5)) | ||
>P : Symbol(P, Decl(file.tsx, 2, 22)) | ||
|
||
public render(): JSX.Element { | ||
>render : Symbol((Anonymous class).render, Decl(file.tsx, 3, 52)) | ||
>JSX : Symbol(JSX, Decl(react.d.ts, 2352, 1)) | ||
>Element : Symbol(JSX.Element, Decl(react.d.ts, 2355, 27)) | ||
|
||
return ( | ||
<Ctor {...this.props } /> | ||
>Ctor : Symbol(Ctor, Decl(file.tsx, 2, 25)) | ||
>this.props : Symbol(React.Component.props, Decl(react.d.ts, 166, 37)) | ||
>this : Symbol((Anonymous class), Decl(file.tsx, 3, 7)) | ||
>props : Symbol(React.Component.props, Decl(react.d.ts, 166, 37)) | ||
|
||
); | ||
} | ||
}; | ||
} |
This file contains 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,41 @@ | ||
=== tests/cases/conformance/jsx/file.tsx === | ||
import React = require('react'); | ||
>React : typeof React | ||
|
||
export function makeP<P>(Ctor: React.ComponentClass<P>): React.ComponentClass<P> { | ||
>makeP : <P>(Ctor: React.ComponentClass<P>) => React.ComponentClass<P> | ||
>P : P | ||
>Ctor : React.ComponentClass<P> | ||
>React : any | ||
>ComponentClass : React.ComponentClass<P> | ||
>P : P | ||
>React : any | ||
>ComponentClass : React.ComponentClass<P> | ||
>P : P | ||
|
||
return class extends React.PureComponent<P, void> { | ||
>class extends React.PureComponent<P, void> { public render(): JSX.Element { return ( <Ctor {...this.props } /> ); } } : typeof (Anonymous class) | ||
>React.PureComponent : React.PureComponent<P, void> | ||
>React : typeof React | ||
>PureComponent : typeof React.PureComponent | ||
>P : P | ||
|
||
public render(): JSX.Element { | ||
>render : () => JSX.Element | ||
>JSX : any | ||
>Element : JSX.Element | ||
|
||
return ( | ||
>( <Ctor {...this.props } /> ) : JSX.Element | ||
|
||
<Ctor {...this.props } /> | ||
><Ctor {...this.props } /> : JSX.Element | ||
>Ctor : React.ComponentClass<P> | ||
>this.props : P & { children?: React.ReactNode; } | ||
>this : this | ||
>props : P & { children?: React.ReactNode; } | ||
|
||
); | ||
} | ||
}; | ||
} |
This file contains 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 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 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 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,16 @@ | ||
// @filename: file.tsx | ||
// @jsx: preserve | ||
// @noLib: true | ||
// @libFiles: react.d.ts,lib.d.ts | ||
|
||
import React = require('react'); | ||
|
||
export function makeP<P>(Ctor: React.ComponentClass<P>): React.ComponentClass<P> { | ||
return class extends React.PureComponent<P, void> { | ||
public render(): JSX.Element { | ||
return ( | ||
<Ctor {...this.props } /> | ||
); | ||
} | ||
}; | ||
} |
This file contains 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 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.
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.
Consider
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.
We use the ternary operator quite often. so do not think this is out of line here.
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.
You would save one condition and make it way easier to read in this case tho