Allow filterType to consider union constraints of non-union types when determining never-ness (#43763)

* Allow filterType to consider union constraints of non-union types when determining never-ness

* Move impl to callback

* Baseline change in narrowing behavior into test, fix post-LKG build
This commit is contained in:
Wesley Wigham
2021-05-05 13:35:09 -07:00
committed by GitHub
parent b83148fe64
commit 456806b070
7 changed files with 935 additions and 3 deletions

View File

@@ -23819,7 +23819,16 @@ namespace ts {
function getNarrowedType(type: Type, candidate: Type, assumeTrue: boolean, isRelated: (source: Type, target: Type) => boolean) {
if (!assumeTrue) {
return filterType(type, t => !isRelated(t, candidate));
return filterType(type, t => {
if (!isRelated(t, candidate)) {
return true;
}
const constraint = getBaseConstraintOfType(t);
if (constraint && constraint !== t) {
return !isRelated(constraint, candidate);
}
return false;
});
}
// If the current type is a union type, remove all constituents that couldn't be instances of
// the candidate type. If one or more constituents remain, return a union of those.

View File

@@ -113,8 +113,8 @@ namespace ts {
return `${newLine}${flattenDiagnosticMessageText(d.messageText, newLine)}${newLine}${newLine}`;
}
export function isBuilderProgram<T extends BuilderProgram>(program: Program | T): program is T {
return !!(program as T).getState;
export function isBuilderProgram(program: Program | BuilderProgram): program is BuilderProgram {
return !!(program as BuilderProgram).getState;
}
export function listFiles<T extends BuilderProgram>(program: Program | T, write: (s: string) => void) {