From c32bb74612bc2d5eb463f6bd20b69ed18da53b15 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 29 Jun 2017 06:43:39 -0700 Subject: [PATCH] Type-check `sum` --- src/compiler/checker.ts | 6 +++--- src/compiler/core.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7cb9902b83149..a033cbca67df0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -84,9 +84,9 @@ namespace ts { // extra cost of calling `getParseTreeNode` when calling these functions from inside the // checker. const checker: TypeChecker = { - getNodeCount: () => sum(host.getSourceFiles(), "nodeCount"), - getIdentifierCount: () => sum(host.getSourceFiles(), "identifierCount"), - getSymbolCount: () => sum(host.getSourceFiles(), "symbolCount") + symbolCount, + getNodeCount: () => sum<"nodeCount">(host.getSourceFiles(), "nodeCount"), + getIdentifierCount: () => sum<"identifierCount">(host.getSourceFiles(), "identifierCount"), + getSymbolCount: () => sum<"symbolCount">(host.getSourceFiles(), "symbolCount") + symbolCount, getTypeCount: () => typeCount, isUndefinedSymbol: symbol => symbol === undefinedSymbol, isArgumentsSymbol: symbol => symbol === argumentsSymbol, diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 86ad483ccc31f..41fa35cf0bcad 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -727,7 +727,7 @@ namespace ts { return result; } - export function sum(array: any[], prop: string): number { + export function sum(array: { [x in K]: number }[], prop: K): number { let result = 0; for (const v of array) { result += v[prop];