Add arrayFromMap utility function

This commit is contained in:
Nathan Shively-Sanders
2017-01-31 10:34:44 -08:00
parent 69e9bfef35
commit 01bc4efc82
2 changed files with 9 additions and 3 deletions

View File

@@ -14609,9 +14609,7 @@ namespace ts {
function checkTypeOfExpression(node: TypeOfExpression): Type {
checkExpression(node.expression);
const types: Type[] = [];
typeofEQFacts.forEach((_, s) => types.push(getLiteralTypeForText(TypeFlags.StringLiteral, s)));
return getUnionType(types);
return getUnionType(arrayFromMap(typeofEQFacts.keys(), s => getLiteralTypeForText(TypeFlags.StringLiteral, s)));
}
function checkVoidExpression(node: VoidExpression): Type {

View File

@@ -895,6 +895,14 @@ namespace ts {
return result;
}
export function arrayFromMap<T, U>(iterator: Iterator<T>, f: (value: T) => U) {
const result: U[] = [];
for (let { value, done } = iterator.next(); !done; { value, done } = iterator.next()) {
result.push(f(value));
}
return result;
}
/**
* Calls `callback` for each entry in the map, returning the first truthy result.
* Use `map.forEach` instead for normal iteration.