Skip to content

Commit 7eb39cc

Browse files
committed
Allow any type for spreads in JsxExpression
1 parent d29c78e commit 7eb39cc

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10905,7 +10905,7 @@ namespace ts {
1090510905
function checkJsxExpression(node: JsxExpression) {
1090610906
if (node.expression) {
1090710907
const type = checkExpression(node.expression);
10908-
if (node.dotDotDotToken && !isArrayType(type)) {
10908+
if (node.dotDotDotToken && type !== anyType && !isArrayType(type)) {
1090910909
error(node, Diagnostics.JSX_spread_child_must_be_an_array_type, node.toString(), typeToString(type));
1091010910
}
1091110911
return type;

tests/baselines/reference/tsxSpreadChildrenInvalidType.errors.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ tests/cases/conformance/jsx/tsxSpreadChildrenInvalidType.tsx(21,9): error TS2609
2727
!!! error TS2609: JSX spread child must be an array type.
2828
</div>;
2929
}
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+
}
3036
let x: TodoListProps;
3137
<TodoList {...x}/>
3238

tests/baselines/reference/tsxSpreadChildrenInvalidType.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ function TodoList({ todos }: TodoListProps) {
2222
{...<Todo key={todos[0].id} todo={todos[0].todo} />}
2323
</div>;
2424
}
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+
}
2531
let x: TodoListProps;
2632
<TodoList {...x}/>
2733

@@ -42,5 +48,10 @@ function TodoList(_a) {
4248
var todos = _a.todos;
4349
return React.createElement("div", null, React.createElement(Todo, { key: todos[0].id, todo: todos[0].todo }));
4450
}
51+
function TodoListNoError(_a) {
52+
var todos = _a.todos;
53+
// any is not checked
54+
return React.createElement("div", null, React.createElement(Todo, { key: todos[0].id, todo: todos[0].todo }));
55+
}
4556
var x;
4657
React.createElement(TodoList, __assign({}, x));

tests/cases/conformance/jsx/tsxSpreadChildrenInvalidType.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,11 @@ function TodoList({ todos }: TodoListProps) {
2222
{...<Todo key={todos[0].id} todo={todos[0].todo} />}
2323
</div>;
2424
}
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+
}
2531
let x: TodoListProps;
2632
<TodoList {...x}/>

0 commit comments

Comments
 (0)