Skip to content

Commit ffc899e

Browse files
authored
Merge pull request #16377 from Microsoft/fix-synthetic-properties-in-hasExcessProperties
Fix synthetic properties in hasExcessProperties
2 parents 9d30ab6 + d3f2234 commit ffc899e

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8977,7 +8977,9 @@ namespace ts {
89778977
reportError(Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(target));
89788978
}
89798979
else {
8980-
errorNode = prop.valueDeclaration;
8980+
if (prop.valueDeclaration) {
8981+
errorNode = prop.valueDeclaration;
8982+
}
89818983
reportError(Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1,
89828984
symbolToString(prop), typeToString(target));
89838985
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
tests/cases/compiler/excessPropertyCheckWithSpread.ts(6,3): error TS2345: Argument of type '{ n: number; a: number; }' is not assignable to parameter of type '{ a: any; }'.
2+
Object literal may only specify known properties, and 'n' does not exist in type '{ a: any; }'.
3+
tests/cases/compiler/excessPropertyCheckWithSpread.ts(16,3): error TS2345: Argument of type '{ opt: string | number; a: number; }' is not assignable to parameter of type '{ a: any; }'.
4+
Object literal may only specify known properties, and 'opt' does not exist in type '{ a: any; }'.
5+
6+
7+
==== tests/cases/compiler/excessPropertyCheckWithSpread.ts (2 errors) ====
8+
declare function f({ a: number }): void
9+
interface I {
10+
readonly n: number;
11+
}
12+
declare let i: I;
13+
f({ a: 1, ...i });
14+
~~~~~~~~~~~~~~
15+
!!! error TS2345: Argument of type '{ n: number; a: number; }' is not assignable to parameter of type '{ a: any; }'.
16+
!!! error TS2345: Object literal may only specify known properties, and 'n' does not exist in type '{ a: any; }'.
17+
18+
interface R {
19+
opt?: number
20+
}
21+
interface L {
22+
opt: string
23+
}
24+
declare let l: L;
25+
declare let r: R;
26+
f({ a: 1, ...l, ...r });
27+
~~~~~~~~~~~~~~~~~~~~
28+
!!! error TS2345: Argument of type '{ opt: string | number; a: number; }' is not assignable to parameter of type '{ a: any; }'.
29+
!!! error TS2345: Object literal may only specify known properties, and 'opt' does not exist in type '{ a: any; }'.
30+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//// [excessPropertyCheckWithSpread.ts]
2+
declare function f({ a: number }): void
3+
interface I {
4+
readonly n: number;
5+
}
6+
declare let i: I;
7+
f({ a: 1, ...i });
8+
9+
interface R {
10+
opt?: number
11+
}
12+
interface L {
13+
opt: string
14+
}
15+
declare let l: L;
16+
declare let r: R;
17+
f({ a: 1, ...l, ...r });
18+
19+
20+
//// [excessPropertyCheckWithSpread.js]
21+
var __assign = (this && this.__assign) || Object.assign || function(t) {
22+
for (var s, i = 1, n = arguments.length; i < n; i++) {
23+
s = arguments[i];
24+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
25+
t[p] = s[p];
26+
}
27+
return t;
28+
};
29+
f(__assign({ a: 1 }, i));
30+
f(__assign({ a: 1 }, l, r));
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
declare function f({ a: number }): void
2+
interface I {
3+
readonly n: number;
4+
}
5+
declare let i: I;
6+
f({ a: 1, ...i });
7+
8+
interface R {
9+
opt?: number
10+
}
11+
interface L {
12+
opt: string
13+
}
14+
declare let l: L;
15+
declare let r: R;
16+
f({ a: 1, ...l, ...r });

0 commit comments

Comments
 (0)