mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 12:32:08 -06:00
fix(57635): duplicate property name error when trying to overwrite early-bound prop with late-bound prop (#57717)
This commit is contained in:
parent
088f25a8bf
commit
316f1805f3
@ -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;
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// export {};
|
||||
|
||||
//// const prop = "abc";
|
||||
|
||||
//// function foo(): void {};
|
||||
//// foo.abc = 10;
|
||||
//// foo[prop] = 10;
|
||||
|
||||
//// interface T0 {
|
||||
//// [prop]: number;
|
||||
//// abc: number;
|
||||
//// }
|
||||
|
||||
verify.noErrors();
|
||||
Loading…
x
Reference in New Issue
Block a user