Skip to content

Commit 4ee8b0f

Browse files
authored
Report excess property errors on object literal names (#53129)
1 parent b1f25a2 commit 4ee8b0f

File tree

102 files changed

+291
-297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+291
-297
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20711,9 +20711,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2071120711
const propDeclaration = prop.valueDeclaration as ObjectLiteralElementLike;
2071220712
Debug.assertNode(propDeclaration, isObjectLiteralElementLike);
2071320713

20714-
errorNode = propDeclaration;
20715-
2071620714
const name = propDeclaration.name!;
20715+
errorNode = name;
20716+
2071720717
if (isIdentifier(name)) {
2071820718
suggestion = getSuggestionForNonexistentProperty(name, errorTarget);
2071920719
}

tests/baselines/reference/arrayCast.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ tests/cases/compiler/arrayCast.ts(3,23): error TS2352: Conversion of type '{ foo
77
// Should fail. Even though the array is contextually typed with { id: number }[], it still
88
// has type { foo: string }[], which is not assignable to { id: number }[].
99
<{ id: number; }[]>[{ foo: "s" }];
10-
~~~~~~~~
10+
~~~
1111
!!! error TS2352: Conversion of type '{ foo: string; }[]' to type '{ id: number; }[]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
1212
!!! error TS2352: Type '{ foo: string; }' is not comparable to type '{ id: number; }'.
1313
!!! error TS2352: Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'.

tests/baselines/reference/arrayLiteralTypeInference.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ tests/cases/compiler/arrayLiteralTypeInference.ts(32,18): error TS2322: Type '{
2323

2424
var x1: Action[] = [
2525
{ id: 2, trueness: false },
26-
~~~~~~~~~~~~~~~
26+
~~~~~~~~
2727
!!! error TS2322: Type '{ id: number; trueness: false; }' is not assignable to type 'Action'.
2828
!!! error TS2322: Object literal may only specify known properties, and 'trueness' does not exist in type 'Action'.
2929
{ id: 3, name: "three" }
30-
~~~~~~~~~~~~~
30+
~~~~
3131
!!! error TS2322: Type '{ id: number; name: string; }' is not assignable to type 'Action'.
3232
!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type 'Action'.
3333
]
@@ -46,11 +46,11 @@ tests/cases/compiler/arrayLiteralTypeInference.ts(32,18): error TS2322: Type '{
4646
var z1: { id: number }[] =
4747
[
4848
{ id: 2, trueness: false },
49-
~~~~~~~~~~~~~~~
49+
~~~~~~~~
5050
!!! error TS2322: Type '{ id: number; trueness: false; }' is not assignable to type '{ id: number; }'.
5151
!!! error TS2322: Object literal may only specify known properties, and 'trueness' does not exist in type '{ id: number; }'.
5252
{ id: 3, name: "three" }
53-
~~~~~~~~~~~~~
53+
~~~~
5454
!!! error TS2322: Type '{ id: number; name: string; }' is not assignable to type '{ id: number; }'.
5555
!!! error TS2322: Object literal may only specify known properties, and 'name' does not exist in type '{ id: number; }'.
5656
]

tests/baselines/reference/arrayLiterals.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts(24,101): erro
2929

3030
// Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[]
3131
var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
32-
~~~~~
32+
~
3333
!!! error TS2322: Type '{ a: string; b: number; c: string; }' is not assignable to type '{ a: string; b: number; }'.
3434
!!! error TS2322: Object literal may only specify known properties, and 'c' does not exist in type '{ a: string; b: number; }'.
3535
!!! related TS6501 tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts:24:17: The expected type comes from this index signature.
36-
~~~~
36+
~
3737
!!! error TS2322: Type '{ a: string; b: number; c: number; }' is not assignable to type '{ a: string; b: number; }'.
3838
!!! error TS2322: Object literal may only specify known properties, and 'c' does not exist in type '{ a: string; b: number; }'.
3939
!!! related TS6501 tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts:24:17: The expected type comes from this index signature.

tests/baselines/reference/assignmentCompatBug2.errors.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ tests/cases/compiler/assignmentCompatBug2.ts(33,1): error TS2741: Property 'm' i
1111

1212
==== tests/cases/compiler/assignmentCompatBug2.ts (6 errors) ====
1313
var b2: { b: number;} = { a: 0 }; // error
14-
~~~~
14+
~
1515
!!! error TS2322: Type '{ a: number; }' is not assignable to type '{ b: number; }'.
1616
!!! error TS2322: Object literal may only specify known properties, and 'a' does not exist in type '{ b: number; }'.
1717

1818
b2 = { a: 0 }; // error
19-
~~~~
19+
~
2020
!!! error TS2322: Type '{ a: number; }' is not assignable to type '{ b: number; }'.
2121
!!! error TS2322: Object literal may only specify known properties, and 'a' does not exist in type '{ b: number; }'.
2222

2323
b2 = {b: 0, a: 0 };
24-
~~~~
24+
~
2525
!!! error TS2322: Type '{ b: number; a: number; }' is not assignable to type '{ b: number; }'.
2626
!!! error TS2322: Object literal may only specify known properties, and 'a' does not exist in type '{ b: number; }'.
2727

tests/baselines/reference/assignmentCompatBug5.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ tests/cases/compiler/assignmentCompatBug5.ts(9,6): error TS2345: Argument of typ
1212
==== tests/cases/compiler/assignmentCompatBug5.ts (5 errors) ====
1313
function foo1(x: { a: number; }) { }
1414
foo1({ b: 5 });
15-
~~~~
15+
~
1616
!!! error TS2345: Argument of type '{ b: number; }' is not assignable to parameter of type '{ a: number; }'.
1717
!!! error TS2345: Object literal may only specify known properties, and 'b' does not exist in type '{ a: number; }'.
1818

tests/baselines/reference/checkJsdocSatisfiesTag1.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
const t1 = /** @satisfies {T1} */ ({ a: 1 });
3030
const t2 = /** @satisfies {T1} */ ({ a: 1, b: 1 });
31-
~~~~
31+
~
3232
!!! error TS1360: Type '{ a: number; b: number; }' does not satisfy the expected type 'T1'.
3333
!!! error TS1360: Object literal may only specify known properties, and 'b' does not exist in type 'T1'.
3434
const t3 = /** @satisfies {T1} */ ({});
@@ -45,7 +45,7 @@
4545
const t6 = /** @satisfies {[number, number]} */ ([1, 2]);
4646
const t7 = /** @satisfies {T4} */ ({ a: 'test' });
4747
const t8 = /** @satisfies {T4} */ ({ a: 'test', b: 'test' });
48-
~~~~~~~~~
48+
~
4949
!!! error TS1360: Type '{ a: string; b: string; }' does not satisfy the expected type 'T4'.
5050
!!! error TS1360: Object literal may only specify known properties, and 'b' does not exist in type 'T4'.
5151

tests/baselines/reference/checkJsdocSatisfiesTag10.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
a: 0,
1111
b: "hello",
1212
x: 8 // Should error, 'x' isn't in 'Keys'
13-
~~~~
13+
~
1414
!!! error TS1360: Type '{ a: number; b: string; x: number; }' does not satisfy the expected type 'Partial<Record<Keys, unknown>>'.
1515
!!! error TS1360: Object literal may only specify known properties, and 'x' does not exist in type 'Partial<Record<Keys, unknown>>'.
1616
});

tests/baselines/reference/checkJsdocSatisfiesTag12.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @satisfies {T1}
3131
*/
3232
const t2 = { a: 1, b: 1 };
33-
~~~~
33+
~
3434
!!! error TS1360: Type '{ a: number; b: number; }' does not satisfy the expected type 'T1'.
3535
!!! error TS1360: Object literal may only specify known properties, and 'b' does not exist in type 'T1'.
3636

@@ -53,7 +53,7 @@
5353
* @satisfies {T2}
5454
*/
5555
const t6 = { a: 'test', b: 'test' };
56-
~~~~~~~~~
56+
~
5757
!!! error TS1360: Type '{ a: string; b: string; }' does not satisfy the expected type 'T2'.
5858
!!! error TS1360: Object literal may only specify known properties, and 'b' does not exist in type 'T2'.
5959

tests/baselines/reference/checkJsdocSatisfiesTag13.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/** @satisfies {{ f: (x: string) => string }} */
1010
const t2 = { g: "oops" }; // should error
11-
~~~~~~~~~
11+
~
1212
!!! error TS1360: Type '{ g: string; }' does not satisfy the expected type '{ f: (x: string) => string; }'.
1313
!!! error TS1360: Object literal may only specify known properties, and 'g' does not exist in type '{ f: (x: string) => string; }'.
1414

0 commit comments

Comments
 (0)