Skip to content

Commit 04bd8cb

Browse files
committed
error on duplicate symbols in classes
1 parent 3af710e commit 04bd8cb

22 files changed

+4165
-310
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12683,7 +12683,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1268312683
// or if we have another early-bound symbol declaration with the same name and
1268412684
// conflicting flags.
1268512685
const earlySymbol = earlySymbols && earlySymbols.get(memberName);
12686-
if (lateSymbol.flags & getExcludedSymbolFlags(symbolFlags) || earlySymbol) {
12686+
// Duplicate property declarations of classes are checked in checkClassForDuplicateDeclarations.
12687+
if (!(parent.flags & SymbolFlags.Class) && (lateSymbol.flags & getExcludedSymbolFlags(symbolFlags) || earlySymbol)) {
1268712688
// If we have an existing early-bound member, combine its declarations so that we can
1268812689
// report an error at each declaration.
1268912690
const declarations = earlySymbol ? concatenate(earlySymbol.declarations, lateSymbol.declarations) : lateSymbol.declarations;
@@ -38878,7 +38879,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3887838879
isStaticMember ? staticNames :
3887938880
instanceNames;
3888038881

38881-
const memberName = name && getPropertyNameForPropertyNameNode(name);
38882+
const memberName = name && getEffectivePropertyNameForPropertyNameNode(name);
3888238883
if (memberName) {
3888338884
switch (member.kind) {
3888438885
case SyntaxKind.GetAccessor:
@@ -38947,7 +38948,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3894738948
const memberNameNode = member.name;
3894838949
const isStaticMember = isStatic(member);
3894938950
if (isStaticMember && memberNameNode) {
38950-
const memberName = getPropertyNameForPropertyNameNode(memberNameNode);
38951+
const memberName = getEffectivePropertyNameForPropertyNameNode(memberNameNode);
3895138952
switch (memberName) {
3895238953
case "name":
3895338954
case "length":

tests/baselines/reference/mappedTypeProperties.errors.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ mappedTypeProperties.ts(23,5): error TS7061: A mapped type may not declare prope
66
mappedTypeProperties.ts(27,5): error TS7061: A mapped type may not declare properties or methods.
77
mappedTypeProperties.ts(31,5): error TS7061: A mapped type may not declare properties or methods.
88
mappedTypeProperties.ts(34,5): error TS7061: A mapped type may not declare properties or methods.
9+
mappedTypeProperties.ts(34,6): error TS2304: Cannot find name 'P'.
10+
mappedTypeProperties.ts(34,11): error TS2693: 'PlaceType' only refers to a type, but is being used as a value here.
911
mappedTypeProperties.ts(37,5): error TS7061: A mapped type may not declare properties or methods.
12+
mappedTypeProperties.ts(37,6): error TS2304: Cannot find name 'P'.
13+
mappedTypeProperties.ts(37,11): error TS2693: 'PlaceType' only refers to a type, but is being used as a value here.
1014
mappedTypeProperties.ts(40,5): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type.
1115
mappedTypeProperties.ts(40,6): error TS2304: Cannot find name 'P'.
1216
mappedTypeProperties.ts(40,6): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
1317
mappedTypeProperties.ts(40,11): error TS2322: Type 'string' is not assignable to type 'object'.
1418
mappedTypeProperties.ts(40,17): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
1519

1620

17-
==== mappedTypeProperties.ts (14 errors) ====
21+
==== mappedTypeProperties.ts (18 errors) ====
1822
export type PlaceType = 'openSky' | 'roofed' | 'garage'
1923
type Before = {
2024
model: 'hour' | 'day';
@@ -65,11 +69,19 @@ mappedTypeProperties.ts(40,17): error TS2363: The right-hand side of an arithmet
6569
[P in PlaceType]: any
6670
~~~~~~~~~~~~~~~~
6771
!!! error TS7061: A mapped type may not declare properties or methods.
72+
~
73+
!!! error TS2304: Cannot find name 'P'.
74+
~~~~~~~~~
75+
!!! error TS2693: 'PlaceType' only refers to a type, but is being used as a value here.
6876
}
6977
const D = class {
7078
[P in PlaceType]: any
7179
~~~~~~~~~~~~~~~~
7280
!!! error TS7061: A mapped type may not declare properties or methods.
81+
~
82+
!!! error TS2304: Cannot find name 'P'.
83+
~~~~~~~~~
84+
!!! error TS2693: 'PlaceType' only refers to a type, but is being used as a value here.
7385
}
7486
const E = class {
7587
[P in 'a' | 'b']: any

0 commit comments

Comments
 (0)