From 3d0fa31a9d3f10896707915966ab7cd2aed33787 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 29 Mar 2016 20:17:20 -0700 Subject: [PATCH] Delete removeNullableKind, use getTypeWithFacts instead --- src/compiler/checker.ts | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 871b485809b..1e05702d978 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2757,7 +2757,7 @@ namespace ts { // In strict null checking mode, if a default value of a non-undefined type is specified, remove // undefined from the final type. if (strictNullChecks && declaration.initializer && !(getNullableKind(checkExpressionCached(declaration.initializer)) & TypeFlags.Undefined)) { - type = removeNullableKind(type, TypeFlags.Undefined); + type = getTypeWithFacts(type, TypeFacts.NEUndefined); } return type; } @@ -6619,35 +6619,8 @@ namespace ts { return type; } - function removeNullableKind(type: Type, kind: TypeFlags) { - if (!(getNullableKind(type) & kind)) { - return type; - } - if (type.flags & TypeFlags.Union) { - let firstType: Type; - let types: Type[]; - for (const t of (type as UnionType).types) { - if (!(t.flags & kind)) { - if (!firstType) { - firstType = t; - } - else { - if (!types) { - types = [firstType]; - } - types.push(t); - } - } - } - if (firstType) { - return types ? getUnionType(types) : firstType; - } - } - return emptyUnionType; - } - function getNonNullableType(type: Type): Type { - return strictNullChecks ? removeNullableKind(type, TypeFlags.Nullable) : type; + return strictNullChecks ? getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull) : type; } /**