Skip to content

Commit 65828c4

Browse files
committed
Spreaded anys should satisfy all required properties
1 parent b3ca009 commit 65828c4

File tree

5 files changed

+85
-4
lines changed

5 files changed

+85
-4
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6830,6 +6830,7 @@ namespace ts {
68306830
nameTable[prop.name] = true;
68316831
}
68326832
}
6833+
return type;
68336834
}
68346835

68356836
/// Returns the type JSX.IntrinsicElements. May return `unknownType` if that type is not present.
@@ -7101,24 +7102,28 @@ namespace ts {
71017102
// Process this array in right-to-left order so we know which
71027103
// attributes (mostly from spreads) are being overwritten and
71037104
// thus should have their types ignored
7105+
let sawSpreadedAny = false;
71047106
for (let i = node.attributes.length - 1; i >= 0; i--) {
71057107
if (node.attributes[i].kind === SyntaxKind.JsxAttribute) {
71067108
checkJsxAttribute(<JsxAttribute>(node.attributes[i]), targetAttributesType, nameTable);
71077109
}
71087110
else {
71097111
Debug.assert(node.attributes[i].kind === SyntaxKind.JsxSpreadAttribute);
7110-
checkJsxSpreadAttribute(<JsxSpreadAttribute>(node.attributes[i]), targetAttributesType, nameTable);
7112+
let spreadType = checkJsxSpreadAttribute(<JsxSpreadAttribute>(node.attributes[i]), targetAttributesType, nameTable);
7113+
if(isTypeAny(spreadType)) {
7114+
sawSpreadedAny = true;
7115+
}
71117116
}
71127117
}
71137118

7114-
// Check that all required properties have been provided
7115-
if (targetAttributesType) {
7119+
// Check that all required properties have been provided. If an 'any'
7120+
// was spreaded in, though, assume that it provided all required properties
7121+
if (targetAttributesType && !sawSpreadedAny) {
71167122
let targetProperties = getPropertiesOfType(targetAttributesType);
71177123
for (let i = 0; i < targetProperties.length; i++) {
71187124
if (!(targetProperties[i].flags & SymbolFlags.Optional) &&
71197125
nameTable[targetProperties[i].name] === undefined) {
71207126

7121-
console.log('oops?');
71227127
error(node, Diagnostics.Property_0_is_missing_in_type_1, targetProperties[i].name, typeToString(targetAttributesType));
71237128
}
71247129
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [tsxAttributeResolution8.tsx]
2+
declare module JSX {
3+
interface Element { }
4+
interface IntrinsicElements {
5+
test1: {x: string};
6+
}
7+
}
8+
9+
var x: any;
10+
// Should be OK
11+
<test1 {...x} />
12+
13+
//// [tsxAttributeResolution8.jsx]
14+
var x;
15+
// Should be OK
16+
<test1 {...x}/>;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== tests/cases/conformance/jsx/tsxAttributeResolution8.tsx ===
2+
declare module JSX {
3+
>JSX : Symbol(JSX, Decl(tsxAttributeResolution8.tsx, 0, 0))
4+
5+
interface Element { }
6+
>Element : Symbol(Element, Decl(tsxAttributeResolution8.tsx, 0, 20))
7+
8+
interface IntrinsicElements {
9+
>IntrinsicElements : Symbol(IntrinsicElements, Decl(tsxAttributeResolution8.tsx, 1, 22))
10+
11+
test1: {x: string};
12+
>test1 : Symbol(test1, Decl(tsxAttributeResolution8.tsx, 2, 30))
13+
>x : Symbol(x, Decl(tsxAttributeResolution8.tsx, 3, 10))
14+
}
15+
}
16+
17+
var x: any;
18+
>x : Symbol(x, Decl(tsxAttributeResolution8.tsx, 7, 3))
19+
20+
// Should be OK
21+
<test1 {...x} />
22+
>test1 : Symbol(JSX.IntrinsicElements.test1, Decl(tsxAttributeResolution8.tsx, 2, 30))
23+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== tests/cases/conformance/jsx/tsxAttributeResolution8.tsx ===
2+
declare module JSX {
3+
>JSX : any
4+
5+
interface Element { }
6+
>Element : Element
7+
8+
interface IntrinsicElements {
9+
>IntrinsicElements : IntrinsicElements
10+
11+
test1: {x: string};
12+
>test1 : { x: string; }
13+
>x : string
14+
}
15+
}
16+
17+
var x: any;
18+
>x : any
19+
20+
// Should be OK
21+
<test1 {...x} />
22+
><test1 {...x} /> : JSX.Element
23+
>test1 : any
24+
>x : any
25+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@filename: file.tsx
2+
//@jsx: preserve
3+
declare module JSX {
4+
interface Element { }
5+
interface IntrinsicElements {
6+
test1: {x: string};
7+
}
8+
}
9+
10+
var x: any;
11+
// Should be OK
12+
<test1 {...x} />

0 commit comments

Comments
 (0)