Skip to content

Commit b54aec1

Browse files
author
Andy
authored
Merge pull request #10153 from Microsoft/tsx_toString
Don't allow properties inherited from Object to be automatically included in TSX attributes
2 parents 18fb33d + 9947ac2 commit b54aec1

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10060,7 +10060,7 @@ namespace ts {
1006010060
for (const prop of props) {
1006110061
// Is there a corresponding property in the element attributes type? Skip checking of properties
1006210062
// that have already been assigned to, as these are not actually pushed into the resulting type
10063-
if (!nameTable[prop.name]) {
10063+
if (!hasProperty(nameTable, prop.name)) {
1006410064
const targetPropSym = getPropertyOfType(elementAttributesType, prop.name);
1006510065
if (targetPropSym) {
1006610066
const msg = chainDiagnosticMessages(undefined, Diagnostics.Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property, prop.name);
@@ -10406,7 +10406,7 @@ namespace ts {
1040610406
const targetProperties = getPropertiesOfType(targetAttributesType);
1040710407
for (let i = 0; i < targetProperties.length; i++) {
1040810408
if (!(targetProperties[i].flags & SymbolFlags.Optional) &&
10409-
nameTable[targetProperties[i].name] === undefined) {
10409+
!hasProperty(nameTable, targetProperties[i].name)) {
1041010410

1041110411
error(node, Diagnostics.Property_0_is_missing_in_type_1, targetProperties[i].name, typeToString(targetAttributesType));
1041210412
}

tests/baselines/reference/tsxAttributeResolution5.errors.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ tests/cases/conformance/jsx/file.tsx(21,16): error TS2606: Property 'x' of JSX s
22
Type 'number' is not assignable to type 'string'.
33
tests/cases/conformance/jsx/file.tsx(25,9): error TS2324: Property 'x' is missing in type 'Attribs1'.
44
tests/cases/conformance/jsx/file.tsx(29,1): error TS2324: Property 'x' is missing in type 'Attribs1'.
5+
tests/cases/conformance/jsx/file.tsx(30,1): error TS2324: Property 'toString' is missing in type 'Attribs2'.
56

67

7-
==== tests/cases/conformance/jsx/file.tsx (3 errors) ====
8+
==== tests/cases/conformance/jsx/file.tsx (4 errors) ====
89
declare module JSX {
910
interface Element { }
1011
interface IntrinsicElements {
@@ -41,5 +42,7 @@ tests/cases/conformance/jsx/file.tsx(29,1): error TS2324: Property 'x' is missin
4142
<test1 {...{}} />; // Error, missing x
4243
~~~~~~~~~~~~~~~~~
4344
!!! error TS2324: Property 'x' is missing in type 'Attribs1'.
44-
<test2 {...{}} />; // OK
45+
<test2 {...{}} />; // Error, missing toString
46+
~~~~~~~~~~~~~~~~~
47+
!!! error TS2324: Property 'toString' is missing in type 'Attribs2'.
4548

tests/baselines/reference/tsxAttributeResolution5.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function make3<T extends {y: string}> (obj: T) {
2828

2929

3030
<test1 {...{}} />; // Error, missing x
31-
<test2 {...{}} />; // OK
31+
<test2 {...{}} />; // Error, missing toString
3232

3333

3434
//// [file.jsx]
@@ -42,4 +42,4 @@ function make3(obj) {
4242
return <test1 {...obj}/>; // Error, missing x
4343
}
4444
<test1 {...{}}/>; // Error, missing x
45-
<test2 {...{}}/>; // OK
45+
<test2 {...{}}/>; // Error, missing toString

tests/cases/conformance/jsx/tsxAttributeResolution5.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ function make3<T extends {y: string}> (obj: T) {
2929

3030

3131
<test1 {...{}} />; // Error, missing x
32-
<test2 {...{}} />; // OK
32+
<test2 {...{}} />; // Error, missing toString

0 commit comments

Comments
 (0)