From d25fd23e042be44026677466cadedbf36f160933 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 10 Jul 2017 14:35:09 -0700 Subject: [PATCH 1/2] Declare 'sum' so that it doesn't require type arguments. --- src/compiler/checker.ts | 6 +++--- src/compiler/core.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ee0a3a90d7e99..5fac69156eb5d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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, diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 745cce8a6cd9d..42faf0b062e22 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -700,10 +700,10 @@ namespace ts { return result; } - export function sum(array: { [x in K]: number }[], prop: K): number { + export function sum, K extends string>(array: T[], prop: K): number { let result = 0; for (const v of array) { - result += v[prop]; + result += (v[prop] as number); } return result; } From 325f4b84cf6cc6f88aa023db91ffb4f3e3fada4e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 11 Jul 2017 15:32:31 -0700 Subject: [PATCH 2/2] Addressed feedback. --- src/compiler/core.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 42faf0b062e22..97b642d8920df 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -703,7 +703,8 @@ namespace ts { export function sum, K extends string>(array: T[], prop: K): number { let result = 0; for (const v of array) { - result += (v[prop] as number); + // Note: we need the following type assertion because of GH #17069 + result += v[prop] as number; } return result; }