@@ -12605,6 +12605,11 @@ namespace ts {
12605
12605
return indexSymbol && getIndexDeclarationOfIndexSymbol(indexSymbol, kind);
12606
12606
}
12607
12607
12608
+ function getIndexDeclarationOfSymbolTable(symbolTable: SymbolTable | undefined, kind: IndexKind): IndexSignatureDeclaration | undefined {
12609
+ const indexSymbol = symbolTable && getIndexSymbolFromSymbolTable(symbolTable);
12610
+ return indexSymbol && getIndexDeclarationOfIndexSymbol(indexSymbol, kind);
12611
+ }
12612
+
12608
12613
function getIndexDeclarationOfIndexSymbol(indexSymbol: Symbol, kind: IndexKind): IndexSignatureDeclaration | undefined {
12609
12614
const syntaxKind = kind === IndexKind.Number ? SyntaxKind.NumberKeyword : SyntaxKind.StringKeyword;
12610
12615
if (indexSymbol?.declarations) {
@@ -36868,15 +36873,16 @@ namespace ts {
36868
36873
}
36869
36874
}
36870
36875
36871
- function checkIndexConstraints(type: Type) {
36872
- const declaredNumberIndexer = getIndexDeclarationOfSymbol( type.symbol, IndexKind.Number);
36873
- const declaredStringIndexer = getIndexDeclarationOfSymbol( type.symbol, IndexKind.String);
36876
+ function checkIndexConstraints(type: Type, isStatic?: boolean ) {
36877
+ const declaredNumberIndexer = getIndexDeclarationOfSymbolTable(isStatic ? type.symbol?.exports : type.symbol?.members , IndexKind.Number);
36878
+ const declaredStringIndexer = getIndexDeclarationOfSymbolTable(isStatic ? type.symbol?.exports : type.symbol?.members , IndexKind.String);
36874
36879
36875
36880
const stringIndexType = getIndexTypeOfType(type, IndexKind.String);
36876
36881
const numberIndexType = getIndexTypeOfType(type, IndexKind.Number);
36877
36882
36878
36883
if (stringIndexType || numberIndexType) {
36879
36884
forEach(getPropertiesOfObjectType(type), prop => {
36885
+ if (isStatic && prop.flags & SymbolFlags.Prototype) return;
36880
36886
const propType = getTypeOfSymbol(prop);
36881
36887
checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, IndexKind.String);
36882
36888
checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, IndexKind.Number);
@@ -36906,11 +36912,6 @@ namespace ts {
36906
36912
const someBaseTypeHasBothIndexers = forEach(getBaseTypes(type as InterfaceType), base => getIndexTypeOfType(base, IndexKind.String) && getIndexTypeOfType(base, IndexKind.Number));
36907
36913
errorNode = someBaseTypeHasBothIndexers || !type.symbol.declarations ? undefined : type.symbol.declarations[0];
36908
36914
}
36909
- if (!errorNode) {
36910
- // `getIndexDeclarationOfSymbol` does not return the declarations for static index signatures, since they
36911
- // come from the __index symbol in the `exports` table of the symbol, and not the `members` table
36912
- errorNode = getIndexInfoOfType(type, IndexKind.Number)?.declaration || getIndexInfoOfType(type, IndexKind.String)?.declaration;
36913
- }
36914
36915
}
36915
36916
36916
36917
if (errorNode && !isTypeAssignableTo(numberIndexType!, stringIndexType!)) { // TODO: GH#18217
@@ -37260,7 +37261,7 @@ namespace ts {
37260
37261
37261
37262
if (produceDiagnostics) {
37262
37263
checkIndexConstraints(type);
37263
- checkIndexConstraints(staticType);
37264
+ checkIndexConstraints(staticType, /*isStatic*/ true );
37264
37265
checkTypeForDuplicateIndexSignatures(node);
37265
37266
checkPropertyInitialization(node);
37266
37267
}
0 commit comments