mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-29 16:29:19 -05:00
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:
@@ -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.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user