@@ -12605,6 +12605,11 @@ namespace ts {
1260512605 return indexSymbol && getIndexDeclarationOfIndexSymbol(indexSymbol, kind);
1260612606 }
1260712607
12608+ function getIndexDeclarationOfSymbolTable(symbolTable: SymbolTable | undefined, kind: IndexKind): IndexSignatureDeclaration | undefined {
12609+ const indexSymbol = symbolTable && getIndexSymbolFromSymbolTable(symbolTable);
12610+ return indexSymbol && getIndexDeclarationOfIndexSymbol(indexSymbol, kind);
12611+ }
12612+
1260812613 function getIndexDeclarationOfIndexSymbol(indexSymbol: Symbol, kind: IndexKind): IndexSignatureDeclaration | undefined {
1260912614 const syntaxKind = kind === IndexKind.Number ? SyntaxKind.NumberKeyword : SyntaxKind.StringKeyword;
1261012615 if (indexSymbol?.declarations) {
@@ -36868,15 +36873,16 @@ namespace ts {
3686836873 }
3686936874 }
3687036875
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);
3687436879
3687536880 const stringIndexType = getIndexTypeOfType(type, IndexKind.String);
3687636881 const numberIndexType = getIndexTypeOfType(type, IndexKind.Number);
3687736882
3687836883 if (stringIndexType || numberIndexType) {
3687936884 forEach(getPropertiesOfObjectType(type), prop => {
36885+ if (isStatic && prop.flags & SymbolFlags.Prototype) return;
3688036886 const propType = getTypeOfSymbol(prop);
3688136887 checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, IndexKind.String);
3688236888 checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, IndexKind.Number);
@@ -36906,11 +36912,6 @@ namespace ts {
3690636912 const someBaseTypeHasBothIndexers = forEach(getBaseTypes(type as InterfaceType), base => getIndexTypeOfType(base, IndexKind.String) && getIndexTypeOfType(base, IndexKind.Number));
3690736913 errorNode = someBaseTypeHasBothIndexers || !type.symbol.declarations ? undefined : type.symbol.declarations[0];
3690836914 }
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- }
3691436915 }
3691536916
3691636917 if (errorNode && !isTypeAssignableTo(numberIndexType!, stringIndexType!)) { // TODO: GH#18217
@@ -37260,7 +37261,7 @@ namespace ts {
3726037261
3726137262 if (produceDiagnostics) {
3726237263 checkIndexConstraints(type);
37263- checkIndexConstraints(staticType);
37264+ checkIndexConstraints(staticType, /*isStatic*/ true );
3726437265 checkTypeForDuplicateIndexSignatures(node);
3726537266 checkPropertyInitialization(node);
3726637267 }
0 commit comments