mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 19:16:17 -06:00
Dedupe some utility code
1. convertToArray is a duplicate of arrayFrom 2. inferFromParameterTypes delegates immediately to inferFromTypes 3. One usage of arrayFrom instantiated a whole iterator only to take the first element, which is the same as calling `next`.
This commit is contained in:
parent
f172f72e76
commit
2eec7f3565
@ -1930,7 +1930,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function createTypeofType() {
|
||||
return getUnionType(convertToArray(typeofEQFacts.keys(), getLiteralType));
|
||||
return getUnionType(arrayFrom(typeofEQFacts.keys(), getLiteralType));
|
||||
}
|
||||
|
||||
// A reserved member name starts with two underscores, but the third character cannot be an underscore
|
||||
@ -10531,12 +10531,8 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function inferFromParameterTypes(source: Type, target: Type) {
|
||||
return inferFromTypes(source, target);
|
||||
}
|
||||
|
||||
function inferFromSignature(source: Signature, target: Signature) {
|
||||
forEachMatchingParameterType(source, target, inferFromParameterTypes);
|
||||
forEachMatchingParameterType(source, target, inferFromTypes);
|
||||
|
||||
if (source.typePredicate && target.typePredicate && source.typePredicate.kind === target.typePredicate.kind) {
|
||||
inferFromTypes(source.typePredicate.type, target.typePredicate.type);
|
||||
|
||||
@ -1290,7 +1290,7 @@ namespace ts {
|
||||
case "object":
|
||||
return {};
|
||||
default:
|
||||
return arrayFrom((<CommandLineOptionOfCustomType>option).type.keys())[0];
|
||||
return (option as CommandLineOptionOfCustomType).type.keys().next().value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -996,14 +996,6 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function convertToArray<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.
|
||||
@ -2527,4 +2519,4 @@ namespace ts {
|
||||
export function isCheckJsEnabledForFile(sourceFile: SourceFile, compilerOptions: CompilerOptions) {
|
||||
return sourceFile.checkJsDirective ? sourceFile.checkJsDirective.enabled : compilerOptions.checkJs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user