Skip to content

Commit 4887673

Browse files
author
Andy
authored
Type-check sum (#16823)
1 parent 91d7b22 commit 4887673

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ namespace ts {
8383
// extra cost of calling `getParseTreeNode` when calling these functions from inside the
8484
// checker.
8585
const checker: TypeChecker = {
86-
getNodeCount: () => sum(host.getSourceFiles(), "nodeCount"),
87-
getIdentifierCount: () => sum(host.getSourceFiles(), "identifierCount"),
88-
getSymbolCount: () => sum(host.getSourceFiles(), "symbolCount") + symbolCount,
86+
getNodeCount: () => sum<"nodeCount">(host.getSourceFiles(), "nodeCount"),
87+
getIdentifierCount: () => sum<"identifierCount">(host.getSourceFiles(), "identifierCount"),
88+
getSymbolCount: () => sum<"symbolCount">(host.getSourceFiles(), "symbolCount") + symbolCount,
8989
getTypeCount: () => typeCount,
9090
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
9191
isArgumentsSymbol: symbol => symbol === argumentsSymbol,

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ namespace ts {
700700
return result;
701701
}
702702

703-
export function sum(array: any[], prop: string): number {
703+
export function sum<K extends string>(array: { [x in K]: number }[], prop: K): number {
704704
let result = 0;
705705
for (const v of array) {
706706
result += v[prop];

0 commit comments

Comments
 (0)