Skip to content

Commit 01b541d

Browse files
committed
Simplify and split + and - test
1 parent 8ef350c commit 01b541d

8 files changed

+180
-64
lines changed

tests/baselines/reference/tsxUnionTypeComponent.errors.txt

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/baselines/reference/tsxUnionTypeComponent.js renamed to tests/baselines/reference/tsxUnionTypeComponent1.js

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,19 @@ interface ComponentProps {
99
class MyComponent extends React.Component<ComponentProps, {}> {
1010
render() {
1111
const { AnyComponent } = this.props;
12-
const someProps = {};
13-
const button = <AnyComponent {...someProps}/>
14-
return (<div>{button}</div>);
12+
return (<AnyComponent />);
1513
}
1614
}
1715

16+
// Stateless Component As Props
1817
<MyComponent AnyComponent={() => <button>test</button>}/>
1918

19+
// Component Class as Props
2020
class MyButtonComponent extends React.Component<{},{}> {
2121
}
2222

2323
<MyComponent AnyComponent={MyButtonComponent} />
2424

25-
type Invalid = string | React.ComponentClass<any>;
26-
27-
var X: Invalid = "";
28-
29-
<X /> // Should fail
3025

3126

3227
//// [file.js]
@@ -36,14 +31,6 @@ var __extends = (this && this.__extends) || function (d, b) {
3631
function __() { this.constructor = d; }
3732
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
3833
};
39-
var __assign = (this && this.__assign) || Object.assign || function(t) {
40-
for (var s, i = 1, n = arguments.length; i < n; i++) {
41-
s = arguments[i];
42-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
43-
t[p] = s[p];
44-
}
45-
return t;
46-
};
4734
var React = require('react');
4835
var MyComponent = (function (_super) {
4936
__extends(MyComponent, _super);
@@ -52,13 +39,13 @@ var MyComponent = (function (_super) {
5239
}
5340
MyComponent.prototype.render = function () {
5441
var AnyComponent = this.props.AnyComponent;
55-
var someProps = {};
56-
var button = React.createElement(AnyComponent, __assign({}, someProps));
57-
return (React.createElement("div", null, button));
42+
return (React.createElement(AnyComponent, null));
5843
};
5944
return MyComponent;
6045
}(React.Component));
46+
// Stateless Component As Props
6147
React.createElement(MyComponent, {AnyComponent: function () { return React.createElement("button", null, "test"); }});
48+
// Component Class as Props
6249
var MyButtonComponent = (function (_super) {
6350
__extends(MyButtonComponent, _super);
6451
function MyButtonComponent() {
@@ -67,5 +54,3 @@ var MyButtonComponent = (function (_super) {
6754
return MyButtonComponent;
6855
}(React.Component));
6956
React.createElement(MyComponent, {AnyComponent: MyButtonComponent});
70-
var X = "";
71-
React.createElement(X, null); // Should fail
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
=== tests/cases/conformance/jsx/file.tsx ===
2+
3+
import React = require('react');
4+
>React : Symbol(React, Decl(file.tsx, 0, 0))
5+
6+
interface ComponentProps {
7+
>ComponentProps : Symbol(ComponentProps, Decl(file.tsx, 1, 32))
8+
9+
AnyComponent: React.StatelessComponent<any> | React.ComponentClass<any>;
10+
>AnyComponent : Symbol(ComponentProps.AnyComponent, Decl(file.tsx, 3, 26))
11+
>React : Symbol(React, Decl(file.tsx, 0, 0))
12+
>StatelessComponent : Symbol(React.StatelessComponent, Decl(react.d.ts, 139, 5))
13+
>React : Symbol(React, Decl(file.tsx, 0, 0))
14+
>ComponentClass : Symbol(React.ComponentClass, Decl(react.d.ts, 150, 5))
15+
}
16+
17+
class MyComponent extends React.Component<ComponentProps, {}> {
18+
>MyComponent : Symbol(MyComponent, Decl(file.tsx, 5, 1))
19+
>React.Component : Symbol(React.Component, Decl(react.d.ts, 114, 55))
20+
>React : Symbol(React, Decl(file.tsx, 0, 0))
21+
>Component : Symbol(React.Component, Decl(react.d.ts, 114, 55))
22+
>ComponentProps : Symbol(ComponentProps, Decl(file.tsx, 1, 32))
23+
24+
render() {
25+
>render : Symbol(MyComponent.render, Decl(file.tsx, 7, 63))
26+
27+
const { AnyComponent } = this.props;
28+
>AnyComponent : Symbol(AnyComponent, Decl(file.tsx, 9, 15))
29+
>this.props : Symbol(React.Component.props, Decl(react.d.ts, 122, 30))
30+
>this : Symbol(MyComponent, Decl(file.tsx, 5, 1))
31+
>props : Symbol(React.Component.props, Decl(react.d.ts, 122, 30))
32+
33+
return (<AnyComponent />);
34+
>AnyComponent : Symbol(AnyComponent, Decl(file.tsx, 9, 15))
35+
}
36+
}
37+
38+
// Stateless Component As Props
39+
<MyComponent AnyComponent={() => <button>test</button>}/>
40+
>MyComponent : Symbol(MyComponent, Decl(file.tsx, 5, 1))
41+
>AnyComponent : Symbol(ComponentProps.AnyComponent, Decl(file.tsx, 3, 26))
42+
>button : Symbol(JSX.IntrinsicElements.button, Decl(react.d.ts, 913, 43))
43+
>button : Symbol(JSX.IntrinsicElements.button, Decl(react.d.ts, 913, 43))
44+
45+
// Component Class as Props
46+
class MyButtonComponent extends React.Component<{},{}> {
47+
>MyButtonComponent : Symbol(MyButtonComponent, Decl(file.tsx, 15, 57))
48+
>React.Component : Symbol(React.Component, Decl(react.d.ts, 114, 55))
49+
>React : Symbol(React, Decl(file.tsx, 0, 0))
50+
>Component : Symbol(React.Component, Decl(react.d.ts, 114, 55))
51+
}
52+
53+
<MyComponent AnyComponent={MyButtonComponent} />
54+
>MyComponent : Symbol(MyComponent, Decl(file.tsx, 5, 1))
55+
>AnyComponent : Symbol(ComponentProps.AnyComponent, Decl(file.tsx, 3, 26))
56+
>MyButtonComponent : Symbol(MyButtonComponent, Decl(file.tsx, 15, 57))
57+
58+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
=== tests/cases/conformance/jsx/file.tsx ===
2+
3+
import React = require('react');
4+
>React : typeof React
5+
6+
interface ComponentProps {
7+
>ComponentProps : ComponentProps
8+
9+
AnyComponent: React.StatelessComponent<any> | React.ComponentClass<any>;
10+
>AnyComponent : React.StatelessComponent<any> | React.ComponentClass<any>
11+
>React : any
12+
>StatelessComponent : React.StatelessComponent<P>
13+
>React : any
14+
>ComponentClass : React.ComponentClass<P>
15+
}
16+
17+
class MyComponent extends React.Component<ComponentProps, {}> {
18+
>MyComponent : MyComponent
19+
>React.Component : React.Component<ComponentProps, {}>
20+
>React : typeof React
21+
>Component : typeof React.Component
22+
>ComponentProps : ComponentProps
23+
24+
render() {
25+
>render : () => JSX.Element
26+
27+
const { AnyComponent } = this.props;
28+
>AnyComponent : React.StatelessComponent<any> | React.ComponentClass<any>
29+
>this.props : ComponentProps
30+
>this : this
31+
>props : ComponentProps
32+
33+
return (<AnyComponent />);
34+
>(<AnyComponent />) : JSX.Element
35+
><AnyComponent /> : JSX.Element
36+
>AnyComponent : React.StatelessComponent<any> | React.ComponentClass<any>
37+
}
38+
}
39+
40+
// Stateless Component As Props
41+
<MyComponent AnyComponent={() => <button>test</button>}/>
42+
><MyComponent AnyComponent={() => <button>test</button>}/> : JSX.Element
43+
>MyComponent : typeof MyComponent
44+
>AnyComponent : any
45+
>() => <button>test</button> : () => JSX.Element
46+
><button>test</button> : JSX.Element
47+
>button : any
48+
>button : any
49+
50+
// Component Class as Props
51+
class MyButtonComponent extends React.Component<{},{}> {
52+
>MyButtonComponent : MyButtonComponent
53+
>React.Component : React.Component<{}, {}>
54+
>React : typeof React
55+
>Component : typeof React.Component
56+
}
57+
58+
<MyComponent AnyComponent={MyButtonComponent} />
59+
><MyComponent AnyComponent={MyButtonComponent} /> : JSX.Element
60+
>MyComponent : typeof MyComponent
61+
>AnyComponent : any
62+
>MyButtonComponent : typeof MyButtonComponent
63+
64+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
tests/cases/conformance/jsx/file.tsx(8,2): error TS2604: JSX element type 'X' does not have any construct or call signatures.
2+
3+
4+
==== tests/cases/conformance/jsx/file.tsx (1 errors) ====
5+
6+
import React = require('react');
7+
8+
type Invalid1 = React.ComponentClass<any> | string;
9+
10+
const X: Invalid1 = "Should fail to construct";
11+
12+
<X />;
13+
~
14+
!!! error TS2604: JSX element type 'X' does not have any construct or call signatures.
15+
16+
17+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [file.tsx]
2+
3+
import React = require('react');
4+
5+
type Invalid1 = React.ComponentClass<any> | string;
6+
7+
const X: Invalid1 = "Should fail to construct";
8+
9+
<X />;
10+
11+
12+
13+
14+
//// [file.js]
15+
"use strict";
16+
var React = require('react');
17+
var X = "Should fail to construct";
18+
React.createElement(X, null);

tests/cases/conformance/jsx/tsxUnionTypeComponent.tsx renamed to tests/cases/conformance/jsx/tsxUnionTypeComponent1.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,16 @@ interface ComponentProps {
1212
class MyComponent extends React.Component<ComponentProps, {}> {
1313
render() {
1414
const { AnyComponent } = this.props;
15-
const someProps = {};
16-
const button = <AnyComponent {...someProps}/>
17-
return (<div>{button}</div>);
15+
return (<AnyComponent />);
1816
}
1917
}
2018

19+
// Stateless Component As Props
2120
<MyComponent AnyComponent={() => <button>test</button>}/>
2221

22+
// Component Class as Props
2323
class MyButtonComponent extends React.Component<{},{}> {
2424
}
2525

2626
<MyComponent AnyComponent={MyButtonComponent} />
2727

28-
type Invalid = string | React.ComponentClass<any>;
29-
30-
var X: Invalid = "";
31-
32-
<X /> // Should fail
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @filename: file.tsx
2+
// @jsx: react
3+
// @noLib: true
4+
// @libFiles: react.d.ts,lib.d.ts
5+
6+
import React = require('react');
7+
8+
type Invalid1 = React.ComponentClass<any> | string;
9+
10+
const X: Invalid1 = "Should fail to construct";
11+
12+
<X />;
13+
14+

0 commit comments

Comments
 (0)