Skip to content

Commit 01bc4ef

Browse files
committed
Add arrayFromMap utility function
1 parent 69e9bfe commit 01bc4ef

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14609,9 +14609,7 @@ namespace ts {
1460914609

1461014610
function checkTypeOfExpression(node: TypeOfExpression): Type {
1461114611
checkExpression(node.expression);
14612-
const types: Type[] = [];
14613-
typeofEQFacts.forEach((_, s) => types.push(getLiteralTypeForText(TypeFlags.StringLiteral, s)));
14614-
return getUnionType(types);
14612+
return getUnionType(arrayFromMap(typeofEQFacts.keys(), s => getLiteralTypeForText(TypeFlags.StringLiteral, s)));
1461514613
}
1461614614

1461714615
function checkVoidExpression(node: VoidExpression): Type {

src/compiler/core.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,14 @@ namespace ts {
895895
return result;
896896
}
897897

898+
export function arrayFromMap<T, U>(iterator: Iterator<T>, f: (value: T) => U) {
899+
const result: U[] = [];
900+
for (let { value, done } = iterator.next(); !done; { value, done } = iterator.next()) {
901+
result.push(f(value));
902+
}
903+
return result;
904+
}
905+
898906
/**
899907
* Calls `callback` for each entry in the map, returning the first truthy result.
900908
* Use `map.forEach` instead for normal iteration.

0 commit comments

Comments
 (0)