Allow any type for spreads in JsxExpression

This commit is contained in:
Nathan Shively-Sanders 2016-10-13 10:17:01 -07:00
parent d29c78e718
commit 7eb39cc80c
4 changed files with 24 additions and 1 deletions

View file

@ -10905,7 +10905,7 @@ namespace ts {
function checkJsxExpression(node: JsxExpression) {
if (node.expression) {
const type = checkExpression(node.expression);
if (node.dotDotDotToken && !isArrayType(type)) {
if (node.dotDotDotToken && type !== anyType && !isArrayType(type)) {
error(node, Diagnostics.JSX_spread_child_must_be_an_array_type, node.toString(), typeToString(type));
}
return type;

View file

@ -27,6 +27,12 @@ tests/cases/conformance/jsx/tsxSpreadChildrenInvalidType.tsx(21,9): error TS2609
!!! error TS2609: JSX spread child must be an array type.
</div>;
}
function TodoListNoError({ todos }: TodoListProps) {
// any is not checked
return <div>
{...(<Todo key={todos[0].id} todo={todos[0].todo} /> as any)}
</div>;
}
let x: TodoListProps;
<TodoList {...x}/>

View file

@ -22,6 +22,12 @@ function TodoList({ todos }: TodoListProps) {
{...<Todo key={todos[0].id} todo={todos[0].todo} />}
</div>;
}
function TodoListNoError({ todos }: TodoListProps) {
// any is not checked
return <div>
{...(<Todo key={todos[0].id} todo={todos[0].todo} /> as any)}
</div>;
}
let x: TodoListProps;
<TodoList {...x}/>
@ -42,5 +48,10 @@ function TodoList(_a) {
var todos = _a.todos;
return React.createElement("div", null, React.createElement(Todo, { key: todos[0].id, todo: todos[0].todo }));
}
function TodoListNoError(_a) {
var todos = _a.todos;
// any is not checked
return React.createElement("div", null, React.createElement(Todo, { key: todos[0].id, todo: todos[0].todo }));
}
var x;
React.createElement(TodoList, __assign({}, x));

View file

@ -22,5 +22,11 @@ function TodoList({ todos }: TodoListProps) {
{...<Todo key={todos[0].id} todo={todos[0].todo} />}
</div>;
}
function TodoListNoError({ todos }: TodoListProps) {
// any is not checked
return <div>
{...(<Todo key={todos[0].id} todo={todos[0].todo} /> as any)}
</div>;
}
let x: TodoListProps;
<TodoList {...x}/>