Skip to content

Commit d0dcee0

Browse files
author
Kanchalai Tanglertsampan
committed
Add tests and baselines for union element type
1 parent e90a328 commit d0dcee0

19 files changed

+1018
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [file.tsx]
2+
3+
import React = require('react');
4+
5+
function SFC1(prop: { x: number }) {
6+
return <div>hello</div>;
7+
};
8+
9+
function SFC2(prop: { x: boolean }) {
10+
return <h1>World </h1>;
11+
}
12+
13+
var SFCComp = SFC1 || SFC2;
14+
<SFCComp x />
15+
16+
//// [file.js]
17+
"use strict";
18+
var React = require("react");
19+
function SFC1(prop) {
20+
return React.createElement("div", null, "hello");
21+
}
22+
;
23+
function SFC2(prop) {
24+
return React.createElement("h1", null, "World ");
25+
}
26+
var SFCComp = SFC1 || SFC2;
27+
React.createElement(SFCComp, { x: true });
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=== tests/cases/conformance/jsx/file.tsx ===
2+
3+
import React = require('react');
4+
>React : Symbol(React, Decl(file.tsx, 0, 0))
5+
6+
function SFC1(prop: { x: number }) {
7+
>SFC1 : Symbol(SFC1, Decl(file.tsx, 1, 32))
8+
>prop : Symbol(prop, Decl(file.tsx, 3, 14))
9+
>x : Symbol(x, Decl(file.tsx, 3, 21))
10+
11+
return <div>hello</div>;
12+
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2397, 45))
13+
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2397, 45))
14+
15+
};
16+
17+
function SFC2(prop: { x: boolean }) {
18+
>SFC2 : Symbol(SFC2, Decl(file.tsx, 5, 2))
19+
>prop : Symbol(prop, Decl(file.tsx, 7, 14))
20+
>x : Symbol(x, Decl(file.tsx, 7, 21))
21+
22+
return <h1>World </h1>;
23+
>h1 : Symbol(JSX.IntrinsicElements.h1, Decl(react.d.ts, 2407, 47))
24+
>h1 : Symbol(JSX.IntrinsicElements.h1, Decl(react.d.ts, 2407, 47))
25+
}
26+
27+
var SFCComp = SFC1 || SFC2;
28+
>SFCComp : Symbol(SFCComp, Decl(file.tsx, 11, 3))
29+
>SFC1 : Symbol(SFC1, Decl(file.tsx, 1, 32))
30+
>SFC2 : Symbol(SFC2, Decl(file.tsx, 5, 2))
31+
32+
<SFCComp x />
33+
>SFCComp : Symbol(SFCComp, Decl(file.tsx, 11, 3))
34+
>x : Symbol(x, Decl(file.tsx, 12, 8))
35+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
=== tests/cases/conformance/jsx/file.tsx ===
2+
3+
import React = require('react');
4+
>React : typeof React
5+
6+
function SFC1(prop: { x: number }) {
7+
>SFC1 : (prop: { x: number; }) => JSX.Element
8+
>prop : { x: number; }
9+
>x : number
10+
11+
return <div>hello</div>;
12+
><div>hello</div> : JSX.Element
13+
>div : any
14+
>div : any
15+
16+
};
17+
18+
function SFC2(prop: { x: boolean }) {
19+
>SFC2 : (prop: { x: boolean; }) => JSX.Element
20+
>prop : { x: boolean; }
21+
>x : boolean
22+
23+
return <h1>World </h1>;
24+
><h1>World </h1> : JSX.Element
25+
>h1 : any
26+
>h1 : any
27+
}
28+
29+
var SFCComp = SFC1 || SFC2;
30+
>SFCComp : ((prop: { x: number; }) => JSX.Element) | ((prop: { x: boolean; }) => JSX.Element)
31+
>SFC1 || SFC2 : ((prop: { x: number; }) => JSX.Element) | ((prop: { x: boolean; }) => JSX.Element)
32+
>SFC1 : (prop: { x: number; }) => JSX.Element
33+
>SFC2 : (prop: { x: boolean; }) => JSX.Element
34+
35+
<SFCComp x />
36+
><SFCComp x /> : JSX.Element
37+
>SFCComp : ((prop: { x: number; }) => JSX.Element) | ((prop: { x: boolean; }) => JSX.Element)
38+
>x : true
39+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
tests/cases/conformance/jsx/file.tsx(13,10): error TS2322: Type '{ x: "hi"; }' is not assignable to type '(IntrinsicAttributes & { x: number; }) | (IntrinsicAttributes & { x: boolean; })'.
2+
Type '{ x: "hi"; }' is not assignable to type 'IntrinsicAttributes & { x: boolean; }'.
3+
Type '{ x: "hi"; }' is not assignable to type '{ x: boolean; }'.
4+
Types of property 'x' are incompatible.
5+
Type '"hi"' is not assignable to type 'boolean'.
6+
7+
8+
==== tests/cases/conformance/jsx/file.tsx (1 errors) ====
9+
10+
import React = require('react');
11+
12+
function SFC1(prop: { x: number }) {
13+
return <div>hello</div>;
14+
};
15+
16+
function SFC2(prop: { x: boolean }) {
17+
return <h1>World </h1>;
18+
}
19+
20+
var SFCComp = SFC1 || SFC2;
21+
<SFCComp x={"hi"}/>
22+
~~~~~~~~
23+
!!! error TS2322: Type '{ x: "hi"; }' is not assignable to type '(IntrinsicAttributes & { x: number; }) | (IntrinsicAttributes & { x: boolean; })'.
24+
!!! error TS2322: Type '{ x: "hi"; }' is not assignable to type 'IntrinsicAttributes & { x: boolean; }'.
25+
!!! error TS2322: Type '{ x: "hi"; }' is not assignable to type '{ x: boolean; }'.
26+
!!! error TS2322: Types of property 'x' are incompatible.
27+
!!! error TS2322: Type '"hi"' is not assignable to type 'boolean'.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [file.tsx]
2+
3+
import React = require('react');
4+
5+
function SFC1(prop: { x: number }) {
6+
return <div>hello</div>;
7+
};
8+
9+
function SFC2(prop: { x: boolean }) {
10+
return <h1>World </h1>;
11+
}
12+
13+
var SFCComp = SFC1 || SFC2;
14+
<SFCComp x={"hi"}/>
15+
16+
//// [file.js]
17+
"use strict";
18+
var React = require("react");
19+
function SFC1(prop) {
20+
return React.createElement("div", null, "hello");
21+
}
22+
;
23+
function SFC2(prop) {
24+
return React.createElement("h1", null, "World ");
25+
}
26+
var SFCComp = SFC1 || SFC2;
27+
React.createElement(SFCComp, { x: "hi" });
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//// [file.tsx]
2+
3+
import React = require('react');
4+
5+
class RC1 extends React.Component<{x : number}, {}> {
6+
render() {
7+
return null;
8+
}
9+
}
10+
11+
class RC2 extends React.Component<{ x: string }, {}> {
12+
render() {
13+
return null;
14+
}
15+
private method() { }
16+
}
17+
18+
class RC3 extends React.Component<{}, {}> {
19+
render() {
20+
return null;
21+
}
22+
}
23+
24+
class RC4 extends React.Component<{}, {}> {
25+
render() {
26+
return null;
27+
}
28+
}
29+
30+
var EmptyRCComp = RC3 || RC4;
31+
var PartRCComp = RC1 || RC4;
32+
var RCComp = RC1 || RC2;
33+
// OK
34+
let a = <RCComp x="Hi" />;
35+
let a1 = <EmptyRCComp />;
36+
let a2 = <EmptyRCComp data-prop="hello" />;
37+
let b = <PartRCComp />
38+
let c = <PartRCComp data-extra="hello" />
39+
40+
//// [file.js]
41+
"use strict";
42+
var __extends = (this && this.__extends) || (function () {
43+
var extendStatics = Object.setPrototypeOf ||
44+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
45+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
46+
return function (d, b) {
47+
extendStatics(d, b);
48+
function __() { this.constructor = d; }
49+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
50+
};
51+
})();
52+
var React = require("react");
53+
var RC1 = (function (_super) {
54+
__extends(RC1, _super);
55+
function RC1() {
56+
return _super !== null && _super.apply(this, arguments) || this;
57+
}
58+
RC1.prototype.render = function () {
59+
return null;
60+
};
61+
return RC1;
62+
}(React.Component));
63+
var RC2 = (function (_super) {
64+
__extends(RC2, _super);
65+
function RC2() {
66+
return _super !== null && _super.apply(this, arguments) || this;
67+
}
68+
RC2.prototype.render = function () {
69+
return null;
70+
};
71+
RC2.prototype.method = function () { };
72+
return RC2;
73+
}(React.Component));
74+
var RC3 = (function (_super) {
75+
__extends(RC3, _super);
76+
function RC3() {
77+
return _super !== null && _super.apply(this, arguments) || this;
78+
}
79+
RC3.prototype.render = function () {
80+
return null;
81+
};
82+
return RC3;
83+
}(React.Component));
84+
var RC4 = (function (_super) {
85+
__extends(RC4, _super);
86+
function RC4() {
87+
return _super !== null && _super.apply(this, arguments) || this;
88+
}
89+
RC4.prototype.render = function () {
90+
return null;
91+
};
92+
return RC4;
93+
}(React.Component));
94+
var EmptyRCComp = RC3 || RC4;
95+
var PartRCComp = RC1 || RC4;
96+
var RCComp = RC1 || RC2;
97+
// OK
98+
var a = React.createElement(RCComp, { x: "Hi" });
99+
var a1 = React.createElement(EmptyRCComp, null);
100+
var a2 = React.createElement(EmptyRCComp, { "data-prop": "hello" });
101+
var b = React.createElement(PartRCComp, null);
102+
var c = React.createElement(PartRCComp, { "data-extra": "hello" });
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
=== tests/cases/conformance/jsx/file.tsx ===
2+
3+
import React = require('react');
4+
>React : Symbol(React, Decl(file.tsx, 0, 0))
5+
6+
class RC1 extends React.Component<{x : number}, {}> {
7+
>RC1 : Symbol(RC1, Decl(file.tsx, 1, 32))
8+
>React.Component : Symbol(React.Component, Decl(react.d.ts, 158, 55))
9+
>React : Symbol(React, Decl(file.tsx, 0, 0))
10+
>Component : Symbol(React.Component, Decl(react.d.ts, 158, 55))
11+
>x : Symbol(x, Decl(file.tsx, 3, 35))
12+
13+
render() {
14+
>render : Symbol(RC1.render, Decl(file.tsx, 3, 53))
15+
16+
return null;
17+
}
18+
}
19+
20+
class RC2 extends React.Component<{ x: string }, {}> {
21+
>RC2 : Symbol(RC2, Decl(file.tsx, 7, 1))
22+
>React.Component : Symbol(React.Component, Decl(react.d.ts, 158, 55))
23+
>React : Symbol(React, Decl(file.tsx, 0, 0))
24+
>Component : Symbol(React.Component, Decl(react.d.ts, 158, 55))
25+
>x : Symbol(x, Decl(file.tsx, 9, 35))
26+
27+
render() {
28+
>render : Symbol(RC2.render, Decl(file.tsx, 9, 54))
29+
30+
return null;
31+
}
32+
private method() { }
33+
>method : Symbol(RC2.method, Decl(file.tsx, 12, 5))
34+
}
35+
36+
class RC3 extends React.Component<{}, {}> {
37+
>RC3 : Symbol(RC3, Decl(file.tsx, 14, 1))
38+
>React.Component : Symbol(React.Component, Decl(react.d.ts, 158, 55))
39+
>React : Symbol(React, Decl(file.tsx, 0, 0))
40+
>Component : Symbol(React.Component, Decl(react.d.ts, 158, 55))
41+
42+
render() {
43+
>render : Symbol(RC3.render, Decl(file.tsx, 16, 43))
44+
45+
return null;
46+
}
47+
}
48+
49+
class RC4 extends React.Component<{}, {}> {
50+
>RC4 : Symbol(RC4, Decl(file.tsx, 20, 1))
51+
>React.Component : Symbol(React.Component, Decl(react.d.ts, 158, 55))
52+
>React : Symbol(React, Decl(file.tsx, 0, 0))
53+
>Component : Symbol(React.Component, Decl(react.d.ts, 158, 55))
54+
55+
render() {
56+
>render : Symbol(RC4.render, Decl(file.tsx, 22, 43))
57+
58+
return null;
59+
}
60+
}
61+
62+
var EmptyRCComp = RC3 || RC4;
63+
>EmptyRCComp : Symbol(EmptyRCComp, Decl(file.tsx, 28, 3))
64+
>RC3 : Symbol(RC3, Decl(file.tsx, 14, 1))
65+
>RC4 : Symbol(RC4, Decl(file.tsx, 20, 1))
66+
67+
var PartRCComp = RC1 || RC4;
68+
>PartRCComp : Symbol(PartRCComp, Decl(file.tsx, 29, 3))
69+
>RC1 : Symbol(RC1, Decl(file.tsx, 1, 32))
70+
>RC4 : Symbol(RC4, Decl(file.tsx, 20, 1))
71+
72+
var RCComp = RC1 || RC2;
73+
>RCComp : Symbol(RCComp, Decl(file.tsx, 30, 3))
74+
>RC1 : Symbol(RC1, Decl(file.tsx, 1, 32))
75+
>RC2 : Symbol(RC2, Decl(file.tsx, 7, 1))
76+
77+
// OK
78+
let a = <RCComp x="Hi" />;
79+
>a : Symbol(a, Decl(file.tsx, 32, 3))
80+
>RCComp : Symbol(RCComp, Decl(file.tsx, 30, 3))
81+
>x : Symbol(x, Decl(file.tsx, 32, 15))
82+
83+
let a1 = <EmptyRCComp />;
84+
>a1 : Symbol(a1, Decl(file.tsx, 33, 3))
85+
>EmptyRCComp : Symbol(EmptyRCComp, Decl(file.tsx, 28, 3))
86+
87+
let a2 = <EmptyRCComp data-prop="hello" />;
88+
>a2 : Symbol(a2, Decl(file.tsx, 34, 3))
89+
>EmptyRCComp : Symbol(EmptyRCComp, Decl(file.tsx, 28, 3))
90+
>data-prop : Symbol(data-prop, Decl(file.tsx, 34, 21))
91+
92+
let b = <PartRCComp />
93+
>b : Symbol(b, Decl(file.tsx, 35, 3))
94+
>PartRCComp : Symbol(PartRCComp, Decl(file.tsx, 29, 3))
95+
96+
let c = <PartRCComp data-extra="hello" />
97+
>c : Symbol(c, Decl(file.tsx, 36, 3))
98+
>PartRCComp : Symbol(PartRCComp, Decl(file.tsx, 29, 3))
99+
>data-extra : Symbol(data-extra, Decl(file.tsx, 36, 19))
100+

0 commit comments

Comments
 (0)