Skip to content

Commit d5719fc

Browse files
jablkorbuckton
andcommitted
Target es2015 to skip helper and refine emit
Co-authored-by: Ron Buckton <[email protected]>
1 parent d69eb09 commit d5719fc

9 files changed

+298
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//// [tsxSpreadChildrenInvalidType.tsx]
2+
declare module JSX {
3+
interface Element { }
4+
interface IntrinsicElements {
5+
[s: string]: any;
6+
}
7+
}
8+
declare var React: any;
9+
10+
interface TodoProp {
11+
id: number;
12+
todo: string;
13+
}
14+
interface TodoListProps {
15+
todos: TodoProp[];
16+
}
17+
function Todo(prop: { key: number, todo: string }) {
18+
return <div>{prop.key.toString() + prop.todo}</div>;
19+
}
20+
function TodoList({ todos }: TodoListProps) {
21+
return <div>
22+
{...<Todo key={todos[0].id} todo={todos[0].todo} />}
23+
</div>;
24+
}
25+
function TodoListNoError({ todos }: TodoListProps) {
26+
// any is not checked
27+
return <div>
28+
{...(<Todo key={todos[0].id} todo={todos[0].todo} /> as any)}
29+
</div>;
30+
}
31+
let x: TodoListProps;
32+
<TodoList {...x}/>
33+
34+
35+
//// [tsxSpreadChildrenInvalidType.js]
36+
function Todo(prop) {
37+
return React.createElement("div", null, prop.key.toString() + prop.todo);
38+
}
39+
function TodoList({ todos }) {
40+
return React.createElement("div", null, ...React.createElement(Todo, { key: todos[0].id, todo: todos[0].todo }));
41+
}
42+
function TodoListNoError({ todos }) {
43+
// any is not checked
44+
return React.createElement("div", null, ...React.createElement(Todo, { key: todos[0].id, todo: todos[0].todo }));
45+
}
46+
let x;
47+
React.createElement(TodoList, Object.assign({}, x));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
tests/cases/conformance/jsx/tsxSpreadChildrenInvalidType.tsx(21,9): error TS2609: JSX spread child must be an array type.
2+
3+
4+
==== tests/cases/conformance/jsx/tsxSpreadChildrenInvalidType.tsx (1 errors) ====
5+
declare module JSX {
6+
interface Element { }
7+
interface IntrinsicElements {
8+
[s: string]: any;
9+
}
10+
}
11+
declare var React: any;
12+
13+
interface TodoProp {
14+
id: number;
15+
todo: string;
16+
}
17+
interface TodoListProps {
18+
todos: TodoProp[];
19+
}
20+
function Todo(prop: { key: number, todo: string }) {
21+
return <div>{prop.key.toString() + prop.todo}</div>;
22+
}
23+
function TodoList({ todos }: TodoListProps) {
24+
return <div>
25+
{...<Todo key={todos[0].id} todo={todos[0].todo} />}
26+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27+
!!! error TS2609: JSX spread child must be an array type.
28+
</div>;
29+
}
30+
function TodoListNoError({ todos }: TodoListProps) {
31+
// any is not checked
32+
return <div>
33+
{...(<Todo key={todos[0].id} todo={todos[0].todo} /> as any)}
34+
</div>;
35+
}
36+
let x: TodoListProps;
37+
<TodoList {...x}/>
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
=== tests/cases/conformance/jsx/tsxSpreadChildrenInvalidType.tsx ===
2+
declare module JSX {
3+
>JSX : Symbol(JSX, Decl(tsxSpreadChildrenInvalidType.tsx, 0, 0))
4+
5+
interface Element { }
6+
>Element : Symbol(Element, Decl(tsxSpreadChildrenInvalidType.tsx, 0, 20))
7+
8+
interface IntrinsicElements {
9+
>IntrinsicElements : Symbol(IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22))
10+
11+
[s: string]: any;
12+
>s : Symbol(s, Decl(tsxSpreadChildrenInvalidType.tsx, 3, 3))
13+
}
14+
}
15+
declare var React: any;
16+
>React : Symbol(React, Decl(tsxSpreadChildrenInvalidType.tsx, 6, 11))
17+
18+
interface TodoProp {
19+
>TodoProp : Symbol(TodoProp, Decl(tsxSpreadChildrenInvalidType.tsx, 6, 23))
20+
21+
id: number;
22+
>id : Symbol(TodoProp.id, Decl(tsxSpreadChildrenInvalidType.tsx, 8, 20))
23+
24+
todo: string;
25+
>todo : Symbol(TodoProp.todo, Decl(tsxSpreadChildrenInvalidType.tsx, 9, 15))
26+
}
27+
interface TodoListProps {
28+
>TodoListProps : Symbol(TodoListProps, Decl(tsxSpreadChildrenInvalidType.tsx, 11, 1))
29+
30+
todos: TodoProp[];
31+
>todos : Symbol(TodoListProps.todos, Decl(tsxSpreadChildrenInvalidType.tsx, 12, 25))
32+
>TodoProp : Symbol(TodoProp, Decl(tsxSpreadChildrenInvalidType.tsx, 6, 23))
33+
}
34+
function Todo(prop: { key: number, todo: string }) {
35+
>Todo : Symbol(Todo, Decl(tsxSpreadChildrenInvalidType.tsx, 14, 1))
36+
>prop : Symbol(prop, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 14))
37+
>key : Symbol(key, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 21))
38+
>todo : Symbol(todo, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 34))
39+
40+
return <div>{prop.key.toString() + prop.todo}</div>;
41+
>div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22))
42+
>prop.key.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))
43+
>prop.key : Symbol(key, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 21))
44+
>prop : Symbol(prop, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 14))
45+
>key : Symbol(key, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 21))
46+
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))
47+
>prop.todo : Symbol(todo, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 34))
48+
>prop : Symbol(prop, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 14))
49+
>todo : Symbol(todo, Decl(tsxSpreadChildrenInvalidType.tsx, 15, 34))
50+
>div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22))
51+
}
52+
function TodoList({ todos }: TodoListProps) {
53+
>TodoList : Symbol(TodoList, Decl(tsxSpreadChildrenInvalidType.tsx, 17, 1))
54+
>todos : Symbol(todos, Decl(tsxSpreadChildrenInvalidType.tsx, 18, 19))
55+
>TodoListProps : Symbol(TodoListProps, Decl(tsxSpreadChildrenInvalidType.tsx, 11, 1))
56+
57+
return <div>
58+
>div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22))
59+
60+
{...<Todo key={todos[0].id} todo={todos[0].todo} />}
61+
>Todo : Symbol(Todo, Decl(tsxSpreadChildrenInvalidType.tsx, 14, 1))
62+
>key : Symbol(key, Decl(tsxSpreadChildrenInvalidType.tsx, 20, 17))
63+
>todos[0].id : Symbol(TodoProp.id, Decl(tsxSpreadChildrenInvalidType.tsx, 8, 20))
64+
>todos : Symbol(todos, Decl(tsxSpreadChildrenInvalidType.tsx, 18, 19))
65+
>id : Symbol(TodoProp.id, Decl(tsxSpreadChildrenInvalidType.tsx, 8, 20))
66+
>todo : Symbol(todo, Decl(tsxSpreadChildrenInvalidType.tsx, 20, 35))
67+
>todos[0].todo : Symbol(TodoProp.todo, Decl(tsxSpreadChildrenInvalidType.tsx, 9, 15))
68+
>todos : Symbol(todos, Decl(tsxSpreadChildrenInvalidType.tsx, 18, 19))
69+
>todo : Symbol(TodoProp.todo, Decl(tsxSpreadChildrenInvalidType.tsx, 9, 15))
70+
71+
</div>;
72+
>div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22))
73+
}
74+
function TodoListNoError({ todos }: TodoListProps) {
75+
>TodoListNoError : Symbol(TodoListNoError, Decl(tsxSpreadChildrenInvalidType.tsx, 22, 1))
76+
>todos : Symbol(todos, Decl(tsxSpreadChildrenInvalidType.tsx, 23, 26))
77+
>TodoListProps : Symbol(TodoListProps, Decl(tsxSpreadChildrenInvalidType.tsx, 11, 1))
78+
79+
// any is not checked
80+
return <div>
81+
>div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22))
82+
83+
{...(<Todo key={todos[0].id} todo={todos[0].todo} /> as any)}
84+
>Todo : Symbol(Todo, Decl(tsxSpreadChildrenInvalidType.tsx, 14, 1))
85+
>key : Symbol(key, Decl(tsxSpreadChildrenInvalidType.tsx, 26, 18))
86+
>todos[0].id : Symbol(TodoProp.id, Decl(tsxSpreadChildrenInvalidType.tsx, 8, 20))
87+
>todos : Symbol(todos, Decl(tsxSpreadChildrenInvalidType.tsx, 23, 26))
88+
>id : Symbol(TodoProp.id, Decl(tsxSpreadChildrenInvalidType.tsx, 8, 20))
89+
>todo : Symbol(todo, Decl(tsxSpreadChildrenInvalidType.tsx, 26, 36))
90+
>todos[0].todo : Symbol(TodoProp.todo, Decl(tsxSpreadChildrenInvalidType.tsx, 9, 15))
91+
>todos : Symbol(todos, Decl(tsxSpreadChildrenInvalidType.tsx, 23, 26))
92+
>todo : Symbol(TodoProp.todo, Decl(tsxSpreadChildrenInvalidType.tsx, 9, 15))
93+
94+
</div>;
95+
>div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildrenInvalidType.tsx, 1, 22))
96+
}
97+
let x: TodoListProps;
98+
>x : Symbol(x, Decl(tsxSpreadChildrenInvalidType.tsx, 29, 3))
99+
>TodoListProps : Symbol(TodoListProps, Decl(tsxSpreadChildrenInvalidType.tsx, 11, 1))
100+
101+
<TodoList {...x}/>
102+
>TodoList : Symbol(TodoList, Decl(tsxSpreadChildrenInvalidType.tsx, 17, 1))
103+
>x : Symbol(x, Decl(tsxSpreadChildrenInvalidType.tsx, 29, 3))
104+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
=== tests/cases/conformance/jsx/tsxSpreadChildrenInvalidType.tsx ===
2+
declare module JSX {
3+
interface Element { }
4+
interface IntrinsicElements {
5+
[s: string]: any;
6+
>s : string
7+
}
8+
}
9+
declare var React: any;
10+
>React : any
11+
12+
interface TodoProp {
13+
id: number;
14+
>id : number
15+
16+
todo: string;
17+
>todo : string
18+
}
19+
interface TodoListProps {
20+
todos: TodoProp[];
21+
>todos : TodoProp[]
22+
}
23+
function Todo(prop: { key: number, todo: string }) {
24+
>Todo : (prop: { key: number; todo: string;}) => JSX.Element
25+
>prop : { key: number; todo: string; }
26+
>key : number
27+
>todo : string
28+
29+
return <div>{prop.key.toString() + prop.todo}</div>;
30+
><div>{prop.key.toString() + prop.todo}</div> : JSX.Element
31+
>div : any
32+
>prop.key.toString() + prop.todo : string
33+
>prop.key.toString() : string
34+
>prop.key.toString : (radix?: number) => string
35+
>prop.key : number
36+
>prop : { key: number; todo: string; }
37+
>key : number
38+
>toString : (radix?: number) => string
39+
>prop.todo : string
40+
>prop : { key: number; todo: string; }
41+
>todo : string
42+
>div : any
43+
}
44+
function TodoList({ todos }: TodoListProps) {
45+
>TodoList : ({ todos }: TodoListProps) => JSX.Element
46+
>todos : TodoProp[]
47+
48+
return <div>
49+
><div> {...<Todo key={todos[0].id} todo={todos[0].todo} />} </div> : JSX.Element
50+
>div : any
51+
52+
{...<Todo key={todos[0].id} todo={todos[0].todo} />}
53+
><Todo key={todos[0].id} todo={todos[0].todo} /> : JSX.Element
54+
>Todo : (prop: { key: number; todo: string; }) => JSX.Element
55+
>key : number
56+
>todos[0].id : number
57+
>todos[0] : TodoProp
58+
>todos : TodoProp[]
59+
>0 : 0
60+
>id : number
61+
>todo : string
62+
>todos[0].todo : string
63+
>todos[0] : TodoProp
64+
>todos : TodoProp[]
65+
>0 : 0
66+
>todo : string
67+
68+
</div>;
69+
>div : any
70+
}
71+
function TodoListNoError({ todos }: TodoListProps) {
72+
>TodoListNoError : ({ todos }: TodoListProps) => JSX.Element
73+
>todos : TodoProp[]
74+
75+
// any is not checked
76+
return <div>
77+
><div> {...(<Todo key={todos[0].id} todo={todos[0].todo} /> as any)} </div> : JSX.Element
78+
>div : any
79+
80+
{...(<Todo key={todos[0].id} todo={todos[0].todo} /> as any)}
81+
>(<Todo key={todos[0].id} todo={todos[0].todo} /> as any) : any
82+
><Todo key={todos[0].id} todo={todos[0].todo} /> as any : any
83+
><Todo key={todos[0].id} todo={todos[0].todo} /> : JSX.Element
84+
>Todo : (prop: { key: number; todo: string; }) => JSX.Element
85+
>key : number
86+
>todos[0].id : number
87+
>todos[0] : TodoProp
88+
>todos : TodoProp[]
89+
>0 : 0
90+
>id : number
91+
>todo : string
92+
>todos[0].todo : string
93+
>todos[0] : TodoProp
94+
>todos : TodoProp[]
95+
>0 : 0
96+
>todo : string
97+
98+
</div>;
99+
>div : any
100+
}
101+
let x: TodoListProps;
102+
>x : TodoListProps
103+
104+
<TodoList {...x}/>
105+
><TodoList {...x}/> : JSX.Element
106+
>TodoList : ({ todos }: TodoListProps) => JSX.Element
107+
>x : TodoListProps
108+

tests/cases/conformance/jsx/tsxSpreadChildrenInvalidType.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @jsx: react
2+
// @target: es2015,es5
23
declare module JSX {
34
interface Element { }
45
interface IntrinsicElements {

0 commit comments

Comments
 (0)