mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
naive change and new tests
This commit is contained in:
@@ -6369,7 +6369,7 @@ namespace ts {
|
||||
// Assumed result is true. If check was not for a primitive type, remove all primitive types
|
||||
if (!typeInfo) {
|
||||
return removeTypesFromUnionType(type, /*typeKind*/ TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.Boolean | TypeFlags.ESSymbol,
|
||||
/*isOfTypeKind*/ true, /*allowEmptyUnionResult*/ false);
|
||||
/*isOfTypeKind*/ true, /*allowEmptyUnionResult*/ true);
|
||||
}
|
||||
// Check was for a primitive type, return that primitive type if it is a subtype
|
||||
if (isTypeSubtypeOf(typeInfo.type, type)) {
|
||||
@@ -6377,12 +6377,12 @@ namespace ts {
|
||||
}
|
||||
// Otherwise, remove all types that aren't of the primitive type kind. This can happen when the type is
|
||||
// union of enum types and other types.
|
||||
return removeTypesFromUnionType(type, /*typeKind*/ typeInfo.flags, /*isOfTypeKind*/ false, /*allowEmptyUnionResult*/ false);
|
||||
return removeTypesFromUnionType(type, /*typeKind*/ typeInfo.flags, /*isOfTypeKind*/ false, /*allowEmptyUnionResult*/ true);
|
||||
}
|
||||
else {
|
||||
// Assumed result is false. If check was for a primitive type, remove that primitive type
|
||||
if (typeInfo) {
|
||||
return removeTypesFromUnionType(type, /*typeKind*/ typeInfo.flags, /*isOfTypeKind*/ true, /*allowEmptyUnionResult*/ false);
|
||||
return removeTypesFromUnionType(type, /*typeKind*/ typeInfo.flags, /*isOfTypeKind*/ true, /*allowEmptyUnionResult*/ true);
|
||||
}
|
||||
// Otherwise we don't have enough information to do anything.
|
||||
return type;
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
let strOrBool: string|boolean;
|
||||
if ((typeof strOrBool === 'boolean' && !strOrBool) || typeof strOrBool === 'string') {
|
||||
var label: string = (typeof strOrBool === 'string') ? strOrBool : "other string";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
var x: string|number;
|
||||
|
||||
var r1 = typeof x === "string" && typeof x === "string" ? x.substr : x.toFixed;
|
||||
|
||||
var r2 = !(typeof x === "string" && typeof x === "string") ? x.toFixed : x.substr;
|
||||
|
||||
var r3 = typeof x === "string" || typeof x === "string" ? x.substr : x.toFixed;
|
||||
|
||||
var r4 = !(typeof x === "string" || typeof x === "string") ? x.toFixed : x.substr;
|
||||
Reference in New Issue
Block a user