Treat | undefined like optionality in spread type

This commit is contained in:
Nathan Shively-Sanders
2016-11-09 13:39:42 -08:00
parent e1c50e1c40
commit fcf32c444f

View File

@@ -4523,7 +4523,7 @@ namespace ts {
t;
}
function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: string) {
function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: string): Symbol {
const types = containingType.types;
let props: Symbol[];
// Flags we want to propagate to the result if they exist in all source symbols
@@ -5914,11 +5914,12 @@ namespace ts {
}
if (leftProp.name in members) {
const rightProp = members[leftProp.name];
if (rightProp.flags & SymbolFlags.Optional) {
const rightType = getTypeOfSymbol(rightProp);
if (maybeTypeOfKind(rightType, TypeFlags.Undefined) || rightProp.flags & SymbolFlags.Optional) {
const declarations: Declaration[] = concatenate(leftProp.declarations, rightProp.declarations);
const flags = SymbolFlags.Property | SymbolFlags.Transient | (leftProp.flags & SymbolFlags.Optional);
const result = <TransientSymbol>createSymbol(flags, leftProp.name);
result.type = getUnionType([getTypeOfSymbol(leftProp), getTypeOfSymbol(rightProp)]);
result.type = getUnionType([getTypeOfSymbol(leftProp), getTypeWithFacts(rightType, TypeFacts.NEUndefined)]);
result.leftSpread = leftProp;
result.rightSpread = rightProp;
result.declarations = declarations;