Skip to content

Commit 316f180

Browse files
authored
fix(57635): duplicate property name error when trying to overwrite early-bound prop with late-bound prop (#57717)
1 parent 088f25a commit 316f180

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13073,12 +13073,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1307313073
let lateSymbol = lateSymbols.get(memberName);
1307413074
if (!lateSymbol) lateSymbols.set(memberName, lateSymbol = createSymbol(SymbolFlags.None, memberName, CheckFlags.Late));
1307513075

13076-
// Report an error if a late-bound member has the same name as an early-bound member,
13077-
// or if we have another early-bound symbol declaration with the same name and
13078-
// conflicting flags.
13076+
// Report an error if there's a symbol declaration with the same name and conflicting flags.
1307913077
const earlySymbol = earlySymbols && earlySymbols.get(memberName);
1308013078
// Duplicate property declarations of classes are checked in checkClassForDuplicateDeclarations.
13081-
if (!(parent.flags & SymbolFlags.Class) && (lateSymbol.flags & getExcludedSymbolFlags(symbolFlags) || earlySymbol)) {
13079+
if (!(parent.flags & SymbolFlags.Class) && lateSymbol.flags & getExcludedSymbolFlags(symbolFlags)) {
1308213080
// If we have an existing early-bound member, combine its declarations so that we can
1308313081
// report an error at each declaration.
1308413082
const declarations = earlySymbol ? concatenate(earlySymbol.declarations, lateSymbol.declarations) : lateSymbol.declarations;

tests/baselines/reference/dynamicNamesErrors.errors.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
dynamicNamesErrors.ts(5,5): error TS2718: Duplicate property '1'.
2-
dynamicNamesErrors.ts(6,5): error TS2733: Property '1' was also declared here.
31
dynamicNamesErrors.ts(19,5): error TS2717: Subsequent property declarations must have the same type. Property '[c1]' must be of type 'number', but here has type 'string'.
42
dynamicNamesErrors.ts(24,1): error TS2322: Type 'T2' is not assignable to type 'T1'.
53
Types of property '[c0]' are incompatible.
@@ -9,17 +7,13 @@ dynamicNamesErrors.ts(25,1): error TS2322: Type 'T1' is not assignable to type '
97
Type 'number' is not assignable to type 'string'.
108

119

12-
==== dynamicNamesErrors.ts (5 errors) ====
10+
==== dynamicNamesErrors.ts (3 errors) ====
1311
const c0 = "1";
1412
const c1 = 1;
1513

1614
interface T0 {
1715
[c0]: number;
18-
~~~~
19-
!!! error TS2718: Duplicate property '1'.
2016
1: number;
21-
~
22-
!!! error TS2733: Property '1' was also declared here.
2317
}
2418

2519
interface T1 {

tests/baselines/reference/dynamicNamesErrors.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ interface T0 {
1111
>T0 : Symbol(T0, Decl(dynamicNamesErrors.ts, 1, 13))
1212

1313
[c0]: number;
14-
>[c0] : Symbol(T0[c0], Decl(dynamicNamesErrors.ts, 3, 14))
14+
>[c0] : Symbol(T0[1], Decl(dynamicNamesErrors.ts, 4, 17), Decl(dynamicNamesErrors.ts, 3, 14))
1515
>c0 : Symbol(c0, Decl(dynamicNamesErrors.ts, 0, 5))
1616

1717
1: number;
18-
>1 : Symbol(T0[1], Decl(dynamicNamesErrors.ts, 4, 17))
18+
>1 : Symbol(T0[1], Decl(dynamicNamesErrors.ts, 4, 17), Decl(dynamicNamesErrors.ts, 3, 14))
1919
}
2020

2121
interface T1 {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
//// export {};
4+
5+
//// const prop = "abc";
6+
7+
//// function foo(): void {};
8+
//// foo.abc = 10;
9+
//// foo[prop] = 10;
10+
11+
//// interface T0 {
12+
//// [prop]: number;
13+
//// abc: number;
14+
//// }
15+
16+
verify.noErrors();

0 commit comments

Comments
 (0)