diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts
index f361657e2f8..5833d2e9c8c 100644
--- a/src/compiler/checker.ts
+++ b/src/compiler/checker.ts
@@ -13040,15 +13040,10 @@ namespace ts {
// JsxAttributes has an object-literal flag and undergo same type-assignablity check as normal object-literal.
// However, using an object-literal error message will be very confusing to the users so we give different a message.
// TODO: Spelling suggestions for excess jsx attributes (needs new diagnostic messages)
-
- if (errorNode && isJsxOpeningLikeElement(errorNode.parent)) {
- const attributes = errorNode.parent.attributes;
- for (const jsxProperty of attributes.properties) {
- if (jsxProperty.kind === SyntaxKind.JsxAttribute && jsxProperty.name.escapedText === prop.escapedName) {
- // Move the error node to the actual JSX property, instead of pointing to the identifier in the JSX element.
- errorNode = jsxProperty;
- }
- }
+ if (prop.valueDeclaration && isNamedDeclaration(prop.valueDeclaration) && prop.valueDeclaration.name && prop.valueDeclaration.name.pos !== -1) {
+ // If the "children" attribute is extraneous `extra` then the declaration's name has no location.
+ // In that case, do not update the error location, since there's no name to point to.
+ errorNode = prop.valueDeclaration.name;
}
reportError(Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(errorTarget));
}
diff --git a/tests/baselines/reference/tsxAttributeResolution1.errors.txt b/tests/baselines/reference/tsxAttributeResolution1.errors.txt
index 00e35caf3a2..46ccb39e704 100644
--- a/tests/baselines/reference/tsxAttributeResolution1.errors.txt
+++ b/tests/baselines/reference/tsxAttributeResolution1.errors.txt
@@ -38,11 +38,11 @@ tests/cases/conformance/jsx/file.tsx(30,8): error TS2322: Type 'number' is not a
!!! error TS2322: Type 'string' is not assignable to type 'number'.
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:10:2: The expected type comes from property 'x' which is declared here on type 'Attribs1'
; // Error, no property "y"
- ~~~~~
+ ~
!!! error TS2322: Type '{ y: number; }' is not assignable to type 'Attribs1'.
!!! error TS2322: Property 'y' does not exist on type 'Attribs1'.
; // Error, no property "y"
- ~~~~~~~
+ ~
!!! error TS2322: Type '{ y: string; }' is not assignable to type 'Attribs1'.
!!! error TS2322: Property 'y' does not exist on type 'Attribs1'.
; // Error, "32" is not number
@@ -50,7 +50,7 @@ tests/cases/conformance/jsx/file.tsx(30,8): error TS2322: Type 'number' is not a
!!! error TS2322: Type 'string' is not assignable to type 'number'.
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:10:2: The expected type comes from property 'x' which is declared here on type 'Attribs1'
; // Error, no 'var' property
- ~~~~~~~~
+ ~~~
!!! error TS2322: Type '{ var: string; }' is not assignable to type 'Attribs1'.
!!! error TS2322: Property 'var' does not exist on type 'Attribs1'.
diff --git a/tests/baselines/reference/tsxAttributeResolution11.errors.txt b/tests/baselines/reference/tsxAttributeResolution11.errors.txt
index 163932ce2e0..d490faad314 100644
--- a/tests/baselines/reference/tsxAttributeResolution11.errors.txt
+++ b/tests/baselines/reference/tsxAttributeResolution11.errors.txt
@@ -27,7 +27,7 @@ tests/cases/conformance/jsx/file.tsx(11,22): error TS2322: Type '{ bar: string;
// Should be an OK
var x = ;
- ~~~~~~~~~~~
+ ~~~
!!! error TS2322: Type '{ bar: string; }' is not assignable to type 'IntrinsicAttributes & { ref?: string; }'.
!!! error TS2322: Property 'bar' does not exist on type 'IntrinsicAttributes & { ref?: string; }'.
diff --git a/tests/baselines/reference/tsxAttributeResolution15.errors.txt b/tests/baselines/reference/tsxAttributeResolution15.errors.txt
index b147464b840..7ec97ba4675 100644
--- a/tests/baselines/reference/tsxAttributeResolution15.errors.txt
+++ b/tests/baselines/reference/tsxAttributeResolution15.errors.txt
@@ -15,7 +15,7 @@ tests/cases/conformance/jsx/file.tsx(14,44): error TS7017: Element implicitly ha
// Error
let a =
- ~~~~~~~~~~~~~
+ ~~~~~
!!! error TS2322: Type '{ prop1: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & { children?: ReactNode; }'.
!!! error TS2322: Property 'prop1' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & { children?: ReactNode; }'.
diff --git a/tests/baselines/reference/tsxElementResolution11.errors.txt b/tests/baselines/reference/tsxElementResolution11.errors.txt
index 59ce93a4ccf..cc032610e2b 100644
--- a/tests/baselines/reference/tsxElementResolution11.errors.txt
+++ b/tests/baselines/reference/tsxElementResolution11.errors.txt
@@ -20,7 +20,7 @@ tests/cases/conformance/jsx/file.tsx(17,7): error TS2322: Type '{ x: number; }'
}
var Obj2: Obj2type;
; // Error
- ~~~~~~
+ ~
!!! error TS2322: Type '{ x: number; }' is not assignable to type '{ q?: number; }'.
!!! error TS2322: Property 'x' does not exist on type '{ q?: number; }'.
diff --git a/tests/baselines/reference/tsxElementResolution3.errors.txt b/tests/baselines/reference/tsxElementResolution3.errors.txt
index c5a11b9cbc1..8f8679b3857 100644
--- a/tests/baselines/reference/tsxElementResolution3.errors.txt
+++ b/tests/baselines/reference/tsxElementResolution3.errors.txt
@@ -15,6 +15,6 @@ tests/cases/conformance/jsx/file.tsx(12,7): error TS2322: Type '{ w: string; }'
// Error
;
- ~~~~~~~
+ ~
!!! error TS2322: Type '{ w: string; }' is not assignable to type '{ n: string; }'.
!!! error TS2322: Property 'w' does not exist on type '{ n: string; }'.
\ No newline at end of file
diff --git a/tests/baselines/reference/tsxElementResolution4.errors.txt b/tests/baselines/reference/tsxElementResolution4.errors.txt
index ea2ae7b0073..235adbb199a 100644
--- a/tests/baselines/reference/tsxElementResolution4.errors.txt
+++ b/tests/baselines/reference/tsxElementResolution4.errors.txt
@@ -19,7 +19,7 @@ tests/cases/conformance/jsx/file.tsx(16,7): error TS2322: Type '{ q: string; }'
// Error
;
- ~~~~
+ ~
!!! error TS2322: Type '{ q: string; }' is not assignable to type '{ m: string; }'.
!!! error TS2322: Property 'q' does not exist on type '{ m: string; }'.
\ No newline at end of file
diff --git a/tests/baselines/reference/tsxLibraryManagedAttributes.errors.txt b/tests/baselines/reference/tsxLibraryManagedAttributes.errors.txt
index 6bf817f0c7d..4b4448e42f6 100644
--- a/tests/baselines/reference/tsxLibraryManagedAttributes.errors.txt
+++ b/tests/baselines/reference/tsxLibraryManagedAttributes.errors.txt
@@ -82,7 +82,7 @@ tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(123,49): error TS232
!!! error TS2322: Type '{ foo: number; }' is missing the following properties from type '{ bar: string | number | ReactComponent<{}, {}> | null | undefined; baz: string; }': bar, baz
const c = ;
const d = ; // Error, baz not a valid prop
- ~~~~~~~~~~
+ ~~~
!!! error TS2322: Type '{ bar: string; baz: string; bat: string; }' is not assignable to type 'Defaultize; bar: PropTypeChecker; baz: PropTypeChecker; }>, { foo: number; }>'.
!!! error TS2322: Property 'bat' does not exist on type 'Defaultize; bar: PropTypeChecker; baz: PropTypeChecker; }>, { foo: number; }>'.
const e = ; // bar is nullable/undefinable since it's not marked `isRequired`
@@ -116,7 +116,7 @@ tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(123,49): error TS232
const k = ;
const l = ; // error, no prop named bar
- ~~~~~~~~
+ ~~~
!!! error TS2322: Type '{ foo: number; bar: string; }' is not assignable to type 'Defaultize<{}, { foo: number; }>'.
!!! error TS2322: Property 'bar' does not exist on type 'Defaultize<{}, { foo: number; }>'.
const m = ; // error, wrong type
@@ -145,7 +145,7 @@ tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(123,49): error TS232
!!! error TS2322: Type '{ foo: string; }' is missing the following properties from type '{ bar: string | number | ReactComponent<{}, {}> | null | undefined; baz: number; }': bar, baz
const p = ;
const q = ; // Error, baz not a valid prop
- ~~~~~~~~~~
+ ~~~
!!! error TS2322: Type '{ bar: string; baz: number; bat: string; }' is not assignable to type 'Defaultize; bar: PropTypeChecker; baz: PropTypeChecker; }>, { foo: string; }>'.
!!! error TS2322: Property 'bat' does not exist on type 'Defaultize; bar: PropTypeChecker; baz: PropTypeChecker; }>, { foo: string; }>'.
const r = ; // bar is nullable/undefinable since it's not marked `isRequired`
@@ -181,7 +181,7 @@ tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(123,49): error TS232
const x = ;
const y = ; // error, no prop named bar
- ~~~~~~~~
+ ~~~
!!! error TS2322: Type '{ foo: string; bar: string; }' is not assignable to type 'Defaultize'.
!!! error TS2322: Property 'bar' does not exist on type 'Defaultize'.
const z = ; // error, wrong type
diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution2.errors.txt b/tests/baselines/reference/tsxSpreadAttributesResolution2.errors.txt
index e46732e0cde..a5f36e5ed08 100644
--- a/tests/baselines/reference/tsxSpreadAttributesResolution2.errors.txt
+++ b/tests/baselines/reference/tsxSpreadAttributesResolution2.errors.txt
@@ -48,6 +48,6 @@ tests/cases/conformance/jsx/file.tsx(24,40): error TS2322: Type '{ X: string; x:
!!! error TS2322: Types of property 'x' are incompatible.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
let w1 = ;
- ~~~~~~
+ ~
!!! error TS2322: Type '{ X: string; x: number; y: "2"; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & PoisonedProp & { children?: ReactNode; }'.
!!! error TS2322: Property 'X' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & PoisonedProp & { children?: ReactNode; }'.
\ No newline at end of file
diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload4.errors.txt b/tests/baselines/reference/tsxStatelessFunctionComponentOverload4.errors.txt
index 43935105d84..3a47e329162 100644
--- a/tests/baselines/reference/tsxStatelessFunctionComponentOverload4.errors.txt
+++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload4.errors.txt
@@ -117,7 +117,7 @@ tests/cases/conformance/jsx/file.tsx(36,12): error TS2769: No overload matches t
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:3:43: The expected type comes from property 'yy1' which is declared here on type 'IntrinsicAttributes & { yy: number; yy1: string; }'
const c3 = ; // This is OK becuase all attribute are spread
const c4 = ; // extra property;
- ~~~~~~~~~~
+ ~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(): Element', gave the following error.
!!! error TS2769: Type '{ y1: number; yy: number; yy1: string; }' is not assignable to type 'IntrinsicAttributes'.
diff --git a/tests/baselines/reference/tsxStatelessFunctionComponents1.errors.txt b/tests/baselines/reference/tsxStatelessFunctionComponents1.errors.txt
index a8ba635f7a7..7827c0625a4 100644
--- a/tests/baselines/reference/tsxStatelessFunctionComponents1.errors.txt
+++ b/tests/baselines/reference/tsxStatelessFunctionComponents1.errors.txt
@@ -32,7 +32,7 @@ tests/cases/conformance/jsx/file.tsx(45,11): error TS2559: Type '{ prop1: boolea
let a1 = ;
// Error
let b = ;
- ~~~~~~~~~~~~~~
+ ~~~~~~
!!! error TS2322: Type '{ naaame: string; }' is not assignable to type 'IntrinsicAttributes & { name: string; }'.
!!! error TS2322: Property 'naaame' does not exist on type 'IntrinsicAttributes & { name: string; }'.
@@ -47,7 +47,7 @@ tests/cases/conformance/jsx/file.tsx(45,11): error TS2559: Type '{ prop1: boolea
!!! error TS2322: Type 'number' is not assignable to type 'string'.
// Error
let f = ;
- ~~~~~~~~~~~~~~~
+ ~~~~~~~~~~
!!! error TS2322: Type '{ naaaaaaame: string; }' is not assignable to type 'IntrinsicAttributes & { name?: string; }'.
!!! error TS2322: Property 'naaaaaaame' does not exist on type 'IntrinsicAttributes & { name?: string; }'.
@@ -65,7 +65,7 @@ tests/cases/conformance/jsx/file.tsx(45,11): error TS2559: Type '{ prop1: boolea
!!! error TS2322: Type '{ prop1: true; }' is not assignable to type 'IntrinsicAttributes'.
!!! error TS2322: Property 'prop1' does not exist on type 'IntrinsicAttributes'.
let i1 = x.greeting.substr(10)} />
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~~~
!!! error TS2322: Type '{ ref: (x: any) => any; }' is not assignable to type 'IntrinsicAttributes'.
!!! error TS2322: Property 'ref' does not exist on type 'IntrinsicAttributes'.
diff --git a/tests/baselines/reference/tsxStatelessFunctionComponents2.errors.txt b/tests/baselines/reference/tsxStatelessFunctionComponents2.errors.txt
index 57ef8c2efbf..b6727eb5ca8 100644
--- a/tests/baselines/reference/tsxStatelessFunctionComponents2.errors.txt
+++ b/tests/baselines/reference/tsxStatelessFunctionComponents2.errors.txt
@@ -25,7 +25,7 @@ tests/cases/conformance/jsx/file.tsx(35,26): error TS2339: Property 'propertyNot
let b = ;
// Error - not allowed to specify 'ref' on SFCs
let c = ;
- ~~~~~~~~~~~
+ ~~~
!!! error TS2322: Type '{ ref: string; }' is not assignable to type 'IntrinsicAttributes & { name?: string; }'.
!!! error TS2322: Property 'ref' does not exist on type 'IntrinsicAttributes & { name?: string; }'.