-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #15463: use intersection types to emulate spread in generic react…
… components (#15851) * Fix #15463: use intersection types to emulate spread in generic react components * Fix lint errors * reverse condition
- Loading branch information
Showing
11 changed files
with
197 additions
and
33 deletions.
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