mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Change isTypePresencePossible, accept baseline
This commit is contained in:
@@ -12722,30 +12722,18 @@ namespace ts {
|
||||
return type;
|
||||
}
|
||||
|
||||
function isTypePresencePossible(type: Type, propName: string, shouldHaveProperty: boolean) {
|
||||
function isTypePresencePossible(type: Type, propName: __String, assumeTrue: boolean) {
|
||||
const prop = getPropertyOfType(type, propName);
|
||||
if (!prop) {
|
||||
// if there is NO property:
|
||||
// - but we assume type SHOULD have it then presence of object of following type IS NOT possible
|
||||
// - and we assume type SHOULD NOT have it then presence of object of following type IS possible
|
||||
return !shouldHaveProperty;
|
||||
} else if (prop.flags & SymbolFlags.Optional) {
|
||||
// if there is an optional property:
|
||||
// - and we assume type SHOULD have it then presence of object of following type IS possible
|
||||
// - but assume type SHOULD NOT have it then presence of object of following type IS still possible
|
||||
return true;
|
||||
} else /* if (prop.flags & SymbolFlags.Required) */ {
|
||||
// if there is a required property:
|
||||
// - and we assume type SHOULD have it then presence of object of following type IS possible
|
||||
// - but we assume type SHOULD NOT have it then presence of object of following type IS NOT possible
|
||||
return shouldHaveProperty;
|
||||
if (prop) {
|
||||
return (prop.flags & SymbolFlags.Optional) ? true : assumeTrue;
|
||||
}
|
||||
return !assumeTrue;
|
||||
}
|
||||
|
||||
function narrowByInKeyword(type: Type, literal: LiteralExpression, assumeTrue: boolean) {
|
||||
if ((type.flags & (TypeFlags.Union | TypeFlags.Object)) || (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType)) {
|
||||
const propName = literal.text;
|
||||
return filterType(type, t => isTypePresencePossible(t, propName, /* shouldHaveProperty */ assumeTrue));
|
||||
const propName = escapeLeadingUnderscores(literal.text);
|
||||
return filterType(type, t => isTypePresencePossible(t, propName, /* assumeTrue */ assumeTrue));
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user