diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6298e410ef19e..7cff9af11039d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13073,12 +13073,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { let lateSymbol = lateSymbols.get(memberName); if (!lateSymbol) lateSymbols.set(memberName, lateSymbol = createSymbol(SymbolFlags.None, memberName, CheckFlags.Late)); - // Report an error if a late-bound member has the same name as an early-bound member, - // or if we have another early-bound symbol declaration with the same name and - // conflicting flags. + // Report an error if there's a symbol declaration with the same name and conflicting flags. const earlySymbol = earlySymbols && earlySymbols.get(memberName); // Duplicate property declarations of classes are checked in checkClassForDuplicateDeclarations. - if (!(parent.flags & SymbolFlags.Class) && (lateSymbol.flags & getExcludedSymbolFlags(symbolFlags) || earlySymbol)) { + if (!(parent.flags & SymbolFlags.Class) && lateSymbol.flags & getExcludedSymbolFlags(symbolFlags)) { // If we have an existing early-bound member, combine its declarations so that we can // report an error at each declaration. const declarations = earlySymbol ? concatenate(earlySymbol.declarations, lateSymbol.declarations) : lateSymbol.declarations; diff --git a/tests/baselines/reference/dynamicNamesErrors.errors.txt b/tests/baselines/reference/dynamicNamesErrors.errors.txt index 12ac22e0e9cef..5ad3741bafbe2 100644 --- a/tests/baselines/reference/dynamicNamesErrors.errors.txt +++ b/tests/baselines/reference/dynamicNamesErrors.errors.txt @@ -1,5 +1,3 @@ -dynamicNamesErrors.ts(5,5): error TS2718: Duplicate property '1'. -dynamicNamesErrors.ts(6,5): error TS2733: Property '1' was also declared here. 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'. dynamicNamesErrors.ts(24,1): error TS2322: Type 'T2' is not assignable to type 'T1'. Types of property '[c0]' are incompatible. @@ -9,17 +7,13 @@ dynamicNamesErrors.ts(25,1): error TS2322: Type 'T1' is not assignable to type ' Type 'number' is not assignable to type 'string'. -==== dynamicNamesErrors.ts (5 errors) ==== +==== dynamicNamesErrors.ts (3 errors) ==== const c0 = "1"; const c1 = 1; interface T0 { [c0]: number; - ~~~~ -!!! error TS2718: Duplicate property '1'. 1: number; - ~ -!!! error TS2733: Property '1' was also declared here. } interface T1 { diff --git a/tests/baselines/reference/dynamicNamesErrors.symbols b/tests/baselines/reference/dynamicNamesErrors.symbols index 9e05c9179758b..06eb5614310cf 100644 --- a/tests/baselines/reference/dynamicNamesErrors.symbols +++ b/tests/baselines/reference/dynamicNamesErrors.symbols @@ -11,11 +11,11 @@ interface T0 { >T0 : Symbol(T0, Decl(dynamicNamesErrors.ts, 1, 13)) [c0]: number; ->[c0] : Symbol(T0[c0], Decl(dynamicNamesErrors.ts, 3, 14)) +>[c0] : Symbol(T0[1], Decl(dynamicNamesErrors.ts, 4, 17), Decl(dynamicNamesErrors.ts, 3, 14)) >c0 : Symbol(c0, Decl(dynamicNamesErrors.ts, 0, 5)) 1: number; ->1 : Symbol(T0[1], Decl(dynamicNamesErrors.ts, 4, 17)) +>1 : Symbol(T0[1], Decl(dynamicNamesErrors.ts, 4, 17), Decl(dynamicNamesErrors.ts, 3, 14)) } interface T1 { diff --git a/tests/cases/fourslash/allowLateBoundSymbolsOverwriteEarlyBoundSymbols.ts b/tests/cases/fourslash/allowLateBoundSymbolsOverwriteEarlyBoundSymbols.ts new file mode 100644 index 0000000000000..781bb1a0516dc --- /dev/null +++ b/tests/cases/fourslash/allowLateBoundSymbolsOverwriteEarlyBoundSymbols.ts @@ -0,0 +1,16 @@ +/// + +//// export {}; + +//// const prop = "abc"; + +//// function foo(): void {}; +//// foo.abc = 10; +//// foo[prop] = 10; + +//// interface T0 { +//// [prop]: number; +//// abc: number; +//// } + +verify.noErrors();