mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #17079 from Microsoft/noTypeArgsSum
Declare 'sum' so that it doesn't require type arguments.
This commit is contained in:
@@ -83,9 +83,9 @@ namespace ts {
|
||||
// extra cost of calling `getParseTreeNode` when calling these functions from inside the
|
||||
// checker.
|
||||
const checker: TypeChecker = {
|
||||
getNodeCount: () => sum<"nodeCount">(host.getSourceFiles(), "nodeCount"),
|
||||
getIdentifierCount: () => sum<"identifierCount">(host.getSourceFiles(), "identifierCount"),
|
||||
getSymbolCount: () => sum<"symbolCount">(host.getSourceFiles(), "symbolCount") + symbolCount,
|
||||
getNodeCount: () => sum(host.getSourceFiles(), "nodeCount"),
|
||||
getIdentifierCount: () => sum(host.getSourceFiles(), "identifierCount"),
|
||||
getSymbolCount: () => sum(host.getSourceFiles(), "symbolCount") + symbolCount,
|
||||
getTypeCount: () => typeCount,
|
||||
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
|
||||
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
|
||||
|
||||
@@ -710,10 +710,11 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function sum<K extends string>(array: { [x in K]: number }[], prop: K): number {
|
||||
export function sum<T extends Record<K, number>, K extends string>(array: T[], prop: K): number {
|
||||
let result = 0;
|
||||
for (const v of array) {
|
||||
result += v[prop];
|
||||
// Note: we need the following type assertion because of GH #17069
|
||||
result += v[prop] as number;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user