Change isTypePresencePossible, accept baseline

This commit is contained in:
IdeaHunter
2017-12-06 01:39:34 +03:00
parent 069f73d0f2
commit 04b9b304a3
8 changed files with 595 additions and 47 deletions

View File

@@ -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;
}