Skip to content

Commit e1c97e1

Browse files
authored
Merge pull request #15568 from Microsoft/master-15455
[Master] Fix #15455
2 parents 975bc76 + b1cfee2 commit e1c97e1

18 files changed

+458
-1
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13438,7 +13438,18 @@ namespace ts {
1343813438
}
1343913439
}
1344013440

13441-
return getUnionType(map(signatures, getReturnTypeOfSignature), /*subtypeReduction*/ true);
13441+
const instantiatedSignatures = [];
13442+
for (const signature of signatures) {
13443+
if (signature.typeParameters) {
13444+
const typeArguments = fillMissingTypeArguments(/*typeArguments*/ undefined, signature.typeParameters, /*minTypeArgumentCount*/ 0);
13445+
instantiatedSignatures.push(getSignatureInstantiation(signature, typeArguments));
13446+
}
13447+
else {
13448+
instantiatedSignatures.push(signature);
13449+
}
13450+
}
13451+
13452+
return getUnionType(map(instantiatedSignatures, getReturnTypeOfSignature), /*subtypeReduction*/ true);
1344213453
}
1344313454

1344413455
/**
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [file.tsx]
2+
import React = require('react');
3+
4+
interface Prop {
5+
a: number,
6+
b: string
7+
}
8+
9+
declare class MyComp<P = Prop> extends React.Component<P, {}> {
10+
internalProp: P;
11+
}
12+
13+
let x = <MyComp a={10} b="hi" />
14+
15+
//// [file.jsx]
16+
"use strict";
17+
exports.__esModule = true;
18+
var React = require("react");
19+
var x = <MyComp a={10} b="hi"/>;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
=== tests/cases/conformance/jsx/file.tsx ===
2+
import React = require('react');
3+
>React : Symbol(React, Decl(file.tsx, 0, 0))
4+
5+
interface Prop {
6+
>Prop : Symbol(Prop, Decl(file.tsx, 0, 32))
7+
8+
a: number,
9+
>a : Symbol(Prop.a, Decl(file.tsx, 2, 16))
10+
11+
b: string
12+
>b : Symbol(Prop.b, Decl(file.tsx, 3, 14))
13+
}
14+
15+
declare class MyComp<P = Prop> extends React.Component<P, {}> {
16+
>MyComp : Symbol(MyComp, Decl(file.tsx, 5, 1))
17+
>P : Symbol(P, Decl(file.tsx, 7, 21))
18+
>Prop : Symbol(Prop, Decl(file.tsx, 0, 32))
19+
>React.Component : Symbol(React.Component, Decl(react.d.ts, 158, 55))
20+
>React : Symbol(React, Decl(file.tsx, 0, 0))
21+
>Component : Symbol(React.Component, Decl(react.d.ts, 158, 55))
22+
>P : Symbol(P, Decl(file.tsx, 7, 21))
23+
24+
internalProp: P;
25+
>internalProp : Symbol(MyComp.internalProp, Decl(file.tsx, 7, 63))
26+
>P : Symbol(P, Decl(file.tsx, 7, 21))
27+
}
28+
29+
let x = <MyComp a={10} b="hi" />
30+
>x : Symbol(x, Decl(file.tsx, 11, 3))
31+
>MyComp : Symbol(MyComp, Decl(file.tsx, 5, 1))
32+
>a : Symbol(a, Decl(file.tsx, 11, 15))
33+
>b : Symbol(b, Decl(file.tsx, 11, 22))
34+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
=== tests/cases/conformance/jsx/file.tsx ===
2+
import React = require('react');
3+
>React : typeof React
4+
5+
interface Prop {
6+
>Prop : Prop
7+
8+
a: number,
9+
>a : number
10+
11+
b: string
12+
>b : string
13+
}
14+
15+
declare class MyComp<P = Prop> extends React.Component<P, {}> {
16+
>MyComp : MyComp<P>
17+
>P : P
18+
>Prop : Prop
19+
>React.Component : React.Component<P, {}>
20+
>React : typeof React
21+
>Component : typeof React.Component
22+
>P : P
23+
24+
internalProp: P;
25+
>internalProp : P
26+
>P : P
27+
}
28+
29+
let x = <MyComp a={10} b="hi" />
30+
>x : JSX.Element
31+
><MyComp a={10} b="hi" /> : JSX.Element
32+
>MyComp : typeof MyComp
33+
>a : number
34+
>10 : 10
35+
>b : string
36+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
tests/cases/conformance/jsx/file.tsx(13,9): error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<MyComp<Prop>> & Prop & { children?: ReactNode; }'.
2+
Type '{}' is not assignable to type 'Prop'.
3+
Property 'a' is missing in type '{}'.
4+
tests/cases/conformance/jsx/file.tsx(14,18): error TS2322: Type '{ a: "hi"; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<MyComp<Prop>> & Prop & { children?: ReactNode; }'.
5+
Type '{ a: "hi"; }' is not assignable to type 'Prop'.
6+
Types of property 'a' are incompatible.
7+
Type '"hi"' is not assignable to type 'number'.
8+
9+
10+
==== tests/cases/conformance/jsx/file.tsx (2 errors) ====
11+
import React = require('react');
12+
13+
interface Prop {
14+
a: number,
15+
b: string
16+
}
17+
18+
declare class MyComp<P = Prop> extends React.Component<P, {}> {
19+
internalProp: P;
20+
}
21+
22+
// Error
23+
let x = <MyComp />
24+
~~~~~~~~~~
25+
!!! error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<MyComp<Prop>> & Prop & { children?: ReactNode; }'.
26+
!!! error TS2322: Type '{}' is not assignable to type 'Prop'.
27+
!!! error TS2322: Property 'a' is missing in type '{}'.
28+
let x1 = <MyComp a="hi"/>
29+
~~~~~~
30+
!!! error TS2322: Type '{ a: "hi"; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<MyComp<Prop>> & Prop & { children?: ReactNode; }'.
31+
!!! error TS2322: Type '{ a: "hi"; }' is not assignable to type 'Prop'.
32+
!!! error TS2322: Types of property 'a' are incompatible.
33+
!!! error TS2322: Type '"hi"' is not assignable to type 'number'.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [file.tsx]
2+
import React = require('react');
3+
4+
interface Prop {
5+
a: number,
6+
b: string
7+
}
8+
9+
declare class MyComp<P = Prop> extends React.Component<P, {}> {
10+
internalProp: P;
11+
}
12+
13+
// Error
14+
let x = <MyComp />
15+
let x1 = <MyComp a="hi"/>
16+
17+
//// [file.jsx]
18+
"use strict";
19+
exports.__esModule = true;
20+
var React = require("react");
21+
// Error
22+
var x = <MyComp />;
23+
var x1 = <MyComp a="hi"/>;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
tests/cases/conformance/jsx/file.tsx(16,17): error TS2322: Type '{ a: 10; b: "hi"; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<MyComp<{}>> & { children?: ReactNode; }'.
2+
Property 'a' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<MyComp<{}>> & { children?: ReactNode; }'.
3+
tests/cases/conformance/jsx/file.tsx(17,18): error TS2322: Type '{ a: "hi"; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<MyComp<{}>> & { children?: ReactNode; }'.
4+
Property 'a' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<MyComp<{}>> & { children?: ReactNode; }'.
5+
6+
7+
==== tests/cases/conformance/jsx/file.tsx (2 errors) ====
8+
import React = require('react');
9+
10+
interface Prop {
11+
a: number,
12+
b: string
13+
}
14+
15+
declare class MyComp<P extends Prop> extends React.Component<P, {}> {
16+
internalProp: P;
17+
}
18+
19+
// OK: we fille in missing type argument with empty object
20+
let x1 = <MyComp />
21+
22+
// Error
23+
let x = <MyComp a={10} b="hi" />
24+
~~~~~~~~~~~~~
25+
!!! error TS2322: Type '{ a: 10; b: "hi"; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<MyComp<{}>> & { children?: ReactNode; }'.
26+
!!! error TS2322: Property 'a' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<MyComp<{}>> & { children?: ReactNode; }'.
27+
let x2 = <MyComp a="hi"/>
28+
~~~~~~
29+
!!! error TS2322: Type '{ a: "hi"; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<MyComp<{}>> & { children?: ReactNode; }'.
30+
!!! error TS2322: Property 'a' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<MyComp<{}>> & { children?: ReactNode; }'.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [file.tsx]
2+
import React = require('react');
3+
4+
interface Prop {
5+
a: number,
6+
b: string
7+
}
8+
9+
declare class MyComp<P extends Prop> extends React.Component<P, {}> {
10+
internalProp: P;
11+
}
12+
13+
// OK: we fille in missing type argument with empty object
14+
let x1 = <MyComp />
15+
16+
// Error
17+
let x = <MyComp a={10} b="hi" />
18+
let x2 = <MyComp a="hi"/>
19+
20+
//// [file.jsx]
21+
"use strict";
22+
exports.__esModule = true;
23+
var React = require("react");
24+
// OK: we fille in missing type argument with empty object
25+
var x1 = <MyComp />;
26+
// Error
27+
var x = <MyComp a={10} b="hi"/>;
28+
var x2 = <MyComp a="hi"/>;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [file.tsx]
2+
import React = require('react')
3+
4+
interface MyComponentProp {
5+
values: string;
6+
}
7+
8+
function MyComponent<T = MyComponentProp>(attr: T) {
9+
return <div>attr.values</div>
10+
}
11+
12+
// OK
13+
let i = <MyComponent values />; // We infer type arguments here
14+
let i1 = <MyComponent values="Hello"/>;
15+
16+
//// [file.jsx]
17+
define(["require", "exports", "react"], function (require, exports, React) {
18+
"use strict";
19+
exports.__esModule = true;
20+
function MyComponent(attr) {
21+
return <div>attr.values</div>;
22+
}
23+
// OK
24+
var i = <MyComponent values/>; // We infer type arguments here
25+
var i1 = <MyComponent values="Hello"/>;
26+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
=== tests/cases/conformance/jsx/file.tsx ===
2+
import React = require('react')
3+
>React : Symbol(React, Decl(file.tsx, 0, 0))
4+
5+
interface MyComponentProp {
6+
>MyComponentProp : Symbol(MyComponentProp, Decl(file.tsx, 0, 31))
7+
8+
values: string;
9+
>values : Symbol(MyComponentProp.values, Decl(file.tsx, 2, 27))
10+
}
11+
12+
function MyComponent<T = MyComponentProp>(attr: T) {
13+
>MyComponent : Symbol(MyComponent, Decl(file.tsx, 4, 1))
14+
>T : Symbol(T, Decl(file.tsx, 6, 21))
15+
>MyComponentProp : Symbol(MyComponentProp, Decl(file.tsx, 0, 31))
16+
>attr : Symbol(attr, Decl(file.tsx, 6, 42))
17+
>T : Symbol(T, Decl(file.tsx, 6, 21))
18+
19+
return <div>attr.values</div>
20+
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
21+
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
22+
}
23+
24+
// OK
25+
let i = <MyComponent values />; // We infer type arguments here
26+
>i : Symbol(i, Decl(file.tsx, 11, 3))
27+
>MyComponent : Symbol(MyComponent, Decl(file.tsx, 4, 1))
28+
>values : Symbol(values, Decl(file.tsx, 11, 20))
29+
30+
let i1 = <MyComponent values="Hello"/>;
31+
>i1 : Symbol(i1, Decl(file.tsx, 12, 3))
32+
>MyComponent : Symbol(MyComponent, Decl(file.tsx, 4, 1))
33+
>values : Symbol(values, Decl(file.tsx, 12, 21))
34+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/conformance/jsx/file.tsx ===
2+
import React = require('react')
3+
>React : typeof React
4+
5+
interface MyComponentProp {
6+
>MyComponentProp : MyComponentProp
7+
8+
values: string;
9+
>values : string
10+
}
11+
12+
function MyComponent<T = MyComponentProp>(attr: T) {
13+
>MyComponent : <T = MyComponentProp>(attr: T) => JSX.Element
14+
>T : T
15+
>MyComponentProp : MyComponentProp
16+
>attr : T
17+
>T : T
18+
19+
return <div>attr.values</div>
20+
><div>attr.values</div> : JSX.Element
21+
>div : any
22+
>div : any
23+
}
24+
25+
// OK
26+
let i = <MyComponent values />; // We infer type arguments here
27+
>i : JSX.Element
28+
><MyComponent values /> : JSX.Element
29+
>MyComponent : <T = MyComponentProp>(attr: T) => JSX.Element
30+
>values : true
31+
32+
let i1 = <MyComponent values="Hello"/>;
33+
>i1 : JSX.Element
34+
><MyComponent values="Hello"/> : JSX.Element
35+
>MyComponent : <T = MyComponentProp>(attr: T) => JSX.Element
36+
>values : string
37+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
tests/cases/conformance/jsx/file.tsx(13,24): error TS2322: Type '{ values: 5; }' is not assignable to type 'IntrinsicAttributes & MyComponentProp'.
2+
Type '{ values: 5; }' is not assignable to type 'MyComponentProp'.
3+
Types of property 'values' are incompatible.
4+
Type '5' is not assignable to type 'string'.
5+
6+
7+
==== tests/cases/conformance/jsx/file.tsx (1 errors) ====
8+
import React = require('react')
9+
10+
interface MyComponentProp {
11+
values: string;
12+
}
13+
14+
function MyComponent1<T extends MyComponentProp>(attr: T) {
15+
return <div>attr.values</div>
16+
}
17+
18+
19+
// Error
20+
let i1 = <MyComponent1 values={5}/>;
21+
~~~~~~~~~~
22+
!!! error TS2322: Type '{ values: 5; }' is not assignable to type 'IntrinsicAttributes & MyComponentProp'.
23+
!!! error TS2322: Type '{ values: 5; }' is not assignable to type 'MyComponentProp'.
24+
!!! error TS2322: Types of property 'values' are incompatible.
25+
!!! error TS2322: Type '5' is not assignable to type 'string'.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [file.tsx]
2+
import React = require('react')
3+
4+
interface MyComponentProp {
5+
values: string;
6+
}
7+
8+
function MyComponent1<T extends MyComponentProp>(attr: T) {
9+
return <div>attr.values</div>
10+
}
11+
12+
13+
// Error
14+
let i1 = <MyComponent1 values={5}/>;
15+
16+
//// [file.jsx]
17+
define(["require", "exports", "react"], function (require, exports, React) {
18+
"use strict";
19+
exports.__esModule = true;
20+
function MyComponent1(attr) {
21+
return <div>attr.values</div>;
22+
}
23+
// Error
24+
var i1 = <MyComponent1 values={5}/>;
25+
});

0 commit comments

Comments
 (0)