Skip to content

Commit 38f6db5

Browse files
Merge pull request microsoft#17079 from Microsoft/noTypeArgsSum
Declare 'sum' so that it doesn't require type arguments.
2 parents 08030c7 + 325f4b8 commit 38f6db5

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
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<"nodeCount">(host.getSourceFiles(), "nodeCount"),
87-
getIdentifierCount: () => sum<"identifierCount">(host.getSourceFiles(), "identifierCount"),
88-
getSymbolCount: () => sum<"symbolCount">(host.getSourceFiles(), "symbolCount") + symbolCount,
86+
getNodeCount: () => sum(host.getSourceFiles(), "nodeCount"),
87+
getIdentifierCount: () => sum(host.getSourceFiles(), "identifierCount"),
88+
getSymbolCount: () => sum(host.getSourceFiles(), "symbolCount") + symbolCount,
8989
getTypeCount: () => typeCount,
9090
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
9191
isArgumentsSymbol: symbol => symbol === argumentsSymbol,

src/compiler/core.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,11 @@ namespace ts {
710710
return result;
711711
}
712712

713-
export function sum<K extends string>(array: { [x in K]: number }[], prop: K): number {
713+
export function sum<T extends Record<K, number>, K extends string>(array: T[], prop: K): number {
714714
let result = 0;
715715
for (const v of array) {
716-
result += v[prop];
716+
// Note: we need the following type assertion because of GH #17069
717+
result += v[prop] as number;
717718
}
718719
return result;
719720
}

0 commit comments

Comments
 (0)