Skip to content

Commit 1c5d4e1

Browse files
authored
Pass symbol under inspection into checkIndexConstraints (microsoft#46350)
1 parent ac34584 commit 1c5d4e1

File tree

4 files changed

+126
-6
lines changed

4 files changed

+126
-6
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34636,7 +34636,7 @@ namespace ts {
3463634636
forEach(node.members, checkSourceElement);
3463734637
if (produceDiagnostics) {
3463834638
const type = getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node);
34639-
checkIndexConstraints(type);
34639+
checkIndexConstraints(type, type.symbol);
3464034640
checkTypeForDuplicateIndexSignatures(node);
3464134641
checkObjectTypeForDuplicateDeclarations(node);
3464234642
}
@@ -38069,7 +38069,7 @@ namespace ts {
3806938069
}
3807038070
}
3807138071

38072-
function checkIndexConstraints(type: Type, isStaticIndex?: boolean) {
38072+
function checkIndexConstraints(type: Type, symbol: Symbol, isStaticIndex?: boolean) {
3807338073
const indexInfos = getIndexInfosOfType(type);
3807438074
if (indexInfos.length === 0) {
3807538075
return;
@@ -38079,7 +38079,7 @@ namespace ts {
3807938079
checkIndexConstraintForProperty(type, prop, getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique, /*includeNonPublic*/ true), getNonMissingTypeOfSymbol(prop));
3808038080
}
3808138081
}
38082-
const typeDeclaration = type.symbol.valueDeclaration;
38082+
const typeDeclaration = symbol.valueDeclaration;
3808338083
if (typeDeclaration && isClassLike(typeDeclaration)) {
3808438084
for (const member of typeDeclaration.members) {
3808538085
// Only process instance properties with computed names here. Static properties cannot be in conflict with indexers,
@@ -38420,8 +38420,8 @@ namespace ts {
3842038420
}
3842138421

3842238422
if (produceDiagnostics) {
38423-
checkIndexConstraints(type);
38424-
checkIndexConstraints(staticType, /*isStaticIndex*/ true);
38423+
checkIndexConstraints(type, symbol);
38424+
checkIndexConstraints(staticType, symbol, /*isStaticIndex*/ true);
3842538425
checkTypeForDuplicateIndexSignatures(node);
3842638426
checkPropertyInitialization(node);
3842738427
}
@@ -38848,7 +38848,7 @@ namespace ts {
3884838848
for (const baseType of getBaseTypes(type)) {
3884938849
checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(baseType, type.thisType), node.name, Diagnostics.Interface_0_incorrectly_extends_interface_1);
3885038850
}
38851-
checkIndexConstraints(type);
38851+
checkIndexConstraints(type, symbol);
3885238852
}
3885338853
}
3885438854
checkObjectTypeForDuplicateDeclarations(node);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
=== tests/cases/compiler/mixinOverMappedTypeNoCrash.ts ===
2+
export type ClassInterface<C> = {
3+
>ClassInterface : Symbol(ClassInterface, Decl(mixinOverMappedTypeNoCrash.ts, 0, 0))
4+
>C : Symbol(C, Decl(mixinOverMappedTypeNoCrash.ts, 0, 27))
5+
6+
[key in keyof C]: C[key];
7+
>key : Symbol(key, Decl(mixinOverMappedTypeNoCrash.ts, 1, 5))
8+
>C : Symbol(C, Decl(mixinOverMappedTypeNoCrash.ts, 0, 27))
9+
>C : Symbol(C, Decl(mixinOverMappedTypeNoCrash.ts, 0, 27))
10+
>key : Symbol(key, Decl(mixinOverMappedTypeNoCrash.ts, 1, 5))
11+
}
12+
13+
type InstanceInterface<I> = {
14+
>InstanceInterface : Symbol(InstanceInterface, Decl(mixinOverMappedTypeNoCrash.ts, 2, 1))
15+
>I : Symbol(I, Decl(mixinOverMappedTypeNoCrash.ts, 4, 23))
16+
17+
new(...args: any[]): I
18+
>args : Symbol(args, Decl(mixinOverMappedTypeNoCrash.ts, 5, 8))
19+
>I : Symbol(I, Decl(mixinOverMappedTypeNoCrash.ts, 4, 23))
20+
21+
prototype: I
22+
>prototype : Symbol(prototype, Decl(mixinOverMappedTypeNoCrash.ts, 5, 26))
23+
>I : Symbol(I, Decl(mixinOverMappedTypeNoCrash.ts, 4, 23))
24+
}
25+
26+
type Constructor<I extends Object, C = any> = ClassInterface<C> & InstanceInterface<I>
27+
>Constructor : Symbol(Constructor, Decl(mixinOverMappedTypeNoCrash.ts, 7, 1))
28+
>I : Symbol(I, Decl(mixinOverMappedTypeNoCrash.ts, 9, 17))
29+
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
30+
>C : Symbol(C, Decl(mixinOverMappedTypeNoCrash.ts, 9, 34))
31+
>ClassInterface : Symbol(ClassInterface, Decl(mixinOverMappedTypeNoCrash.ts, 0, 0))
32+
>C : Symbol(C, Decl(mixinOverMappedTypeNoCrash.ts, 9, 34))
33+
>InstanceInterface : Symbol(InstanceInterface, Decl(mixinOverMappedTypeNoCrash.ts, 2, 1))
34+
>I : Symbol(I, Decl(mixinOverMappedTypeNoCrash.ts, 9, 17))
35+
36+
function cloneClass<T extends Constructor<{}>>(OriginalClass: T): T {
37+
>cloneClass : Symbol(cloneClass, Decl(mixinOverMappedTypeNoCrash.ts, 9, 86))
38+
>T : Symbol(T, Decl(mixinOverMappedTypeNoCrash.ts, 11, 20))
39+
>Constructor : Symbol(Constructor, Decl(mixinOverMappedTypeNoCrash.ts, 7, 1))
40+
>OriginalClass : Symbol(OriginalClass, Decl(mixinOverMappedTypeNoCrash.ts, 11, 47))
41+
>T : Symbol(T, Decl(mixinOverMappedTypeNoCrash.ts, 11, 20))
42+
>T : Symbol(T, Decl(mixinOverMappedTypeNoCrash.ts, 11, 20))
43+
44+
class AnotherOriginalClass extends OriginalClass {
45+
>AnotherOriginalClass : Symbol(AnotherOriginalClass, Decl(mixinOverMappedTypeNoCrash.ts, 11, 69))
46+
>OriginalClass : Symbol(OriginalClass, Decl(mixinOverMappedTypeNoCrash.ts, 11, 47))
47+
48+
constructor(...args: any[]) {
49+
>args : Symbol(args, Decl(mixinOverMappedTypeNoCrash.ts, 13, 20))
50+
51+
super(...args)
52+
>super : Symbol(T, Decl(mixinOverMappedTypeNoCrash.ts, 11, 20))
53+
>args : Symbol(args, Decl(mixinOverMappedTypeNoCrash.ts, 13, 20))
54+
}
55+
}
56+
return AnotherOriginalClass
57+
>AnotherOriginalClass : Symbol(AnotherOriginalClass, Decl(mixinOverMappedTypeNoCrash.ts, 11, 69))
58+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
=== tests/cases/compiler/mixinOverMappedTypeNoCrash.ts ===
2+
export type ClassInterface<C> = {
3+
>ClassInterface : ClassInterface<C>
4+
5+
[key in keyof C]: C[key];
6+
}
7+
8+
type InstanceInterface<I> = {
9+
>InstanceInterface : InstanceInterface<I>
10+
11+
new(...args: any[]): I
12+
>args : any[]
13+
14+
prototype: I
15+
>prototype : I
16+
}
17+
18+
type Constructor<I extends Object, C = any> = ClassInterface<C> & InstanceInterface<I>
19+
>Constructor : Constructor<I, C>
20+
21+
function cloneClass<T extends Constructor<{}>>(OriginalClass: T): T {
22+
>cloneClass : <T extends Constructor<{}, any>>(OriginalClass: T) => T
23+
>OriginalClass : T
24+
25+
class AnotherOriginalClass extends OriginalClass {
26+
>AnotherOriginalClass : AnotherOriginalClass
27+
>OriginalClass : {}
28+
29+
constructor(...args: any[]) {
30+
>args : any[]
31+
32+
super(...args)
33+
>super(...args) : void
34+
>super : T
35+
>...args : any
36+
>args : any[]
37+
}
38+
}
39+
return AnotherOriginalClass
40+
>AnotherOriginalClass : { new (...args: any[]): AnotherOriginalClass; prototype: cloneClass<any>.AnotherOriginalClass; } & T
41+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @noEmit: true
2+
3+
export type ClassInterface<C> = {
4+
[key in keyof C]: C[key];
5+
}
6+
7+
type InstanceInterface<I> = {
8+
new(...args: any[]): I
9+
prototype: I
10+
}
11+
12+
type Constructor<I extends Object, C = any> = ClassInterface<C> & InstanceInterface<I>
13+
14+
function cloneClass<T extends Constructor<{}>>(OriginalClass: T): T {
15+
class AnotherOriginalClass extends OriginalClass {
16+
constructor(...args: any[]) {
17+
super(...args)
18+
}
19+
}
20+
return AnotherOriginalClass
21+
}

0 commit comments

Comments
 (0)