mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 21:06:50 -05:00
Allow discrimination to identical object types when discriminating contextual types (#40574)
* Merge identical object types when discriminating contextual types Co-authored-by: Orta <ortam@microsoft.com> * Allow identical discriminants when discriminating, rather than trying to unify identical union members * Fix lint Co-authored-by: Orta <ortam@microsoft.com>
This commit is contained in:
@@ -18348,8 +18348,18 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
const match = discriminable.indexOf(/*searchElement*/ true);
|
||||
if (match === -1) {
|
||||
return defaultValue;
|
||||
}
|
||||
// make sure exactly 1 matches before returning it
|
||||
return match === -1 || discriminable.indexOf(/*searchElement*/ true, match + 1) !== -1 ? defaultValue : target.types[match];
|
||||
let nextMatch = discriminable.indexOf(/*searchElement*/ true, match + 1);
|
||||
while (nextMatch !== -1) {
|
||||
if (!isTypeIdenticalTo(target.types[match], target.types[nextMatch])) {
|
||||
return defaultValue;
|
||||
}
|
||||
nextMatch = discriminable.indexOf(/*searchElement*/ true, nextMatch + 1);
|
||||
}
|
||||
return target.types[match];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4170,7 +4170,7 @@ namespace ts {
|
||||
export const enum UnionReduction {
|
||||
None = 0,
|
||||
Literal,
|
||||
Subtype
|
||||
Subtype,
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
|
||||
Reference in New Issue
Block a user