2014-11-05 23:47:05 +01:00
=== tests/cases/conformance/expressions/typeGuards/typeGuardsInConditionalExpression.ts ===
// In the true expression of a conditional expression,
// the type of a variable or parameter is narrowed by any type guard in the condition when true,
// provided the true expression contains no assignments to the variable or parameter.
// In the false expression of a conditional expression,
// the type of a variable or parameter is narrowed by any type guard in the condition when false,
// provided the false expression contains no assignments to the variable or parameter.
function foo(x: number | string) {
2015-04-13 23:01:57 +02:00
>foo : (x: string | number) => number, Symbol(foo, Decl(typeGuardsInConditionalExpression.ts, 0, 0))
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 7, 13))
2014-11-05 23:47:05 +01:00
return typeof x === "string"
>typeof x === "string" ? x.length // string : x++ : number
>typeof x === "string" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 7, 13))
2015-04-13 21:36:11 +02:00
>"string" : string
2014-11-05 23:47:05 +01:00
? x.length // string
2015-04-13 23:01:57 +02:00
>x.length : number, Symbol(String.length, Decl(lib.d.ts, 414, 19))
>x : string, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 7, 13))
>length : number, Symbol(String.length, Decl(lib.d.ts, 414, 19))
2014-11-05 23:47:05 +01:00
: x++; // number
>x++ : number
2015-04-13 23:01:57 +02:00
>x : number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 7, 13))
2014-11-05 23:47:05 +01:00
}
function foo2(x: number | string) {
2015-04-13 23:01:57 +02:00
>foo2 : (x: string | number) => string | number, Symbol(foo2, Decl(typeGuardsInConditionalExpression.ts, 11, 1))
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 12, 14))
2014-11-05 23:47:05 +01:00
// x is assigned in the if true branch, the type is not narrowed
return typeof x === "string"
>typeof x === "string" ? (x = 10 && x)// string | number : x : string | number
>typeof x === "string" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 12, 14))
2015-04-13 21:36:11 +02:00
>"string" : string
2014-11-05 23:47:05 +01:00
? (x = 10 && x)// string | number
>(x = 10 && x) : string | number
>x = 10 && x : string | number
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 12, 14))
2014-11-05 23:47:05 +01:00
>10 && x : string | number
2015-04-13 21:36:11 +02:00
>10 : number
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 12, 14))
2014-11-05 23:47:05 +01:00
: x; // string | number
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 12, 14))
2014-11-05 23:47:05 +01:00
}
function foo3(x: number | string) {
2015-04-13 23:01:57 +02:00
>foo3 : (x: string | number) => string | number, Symbol(foo3, Decl(typeGuardsInConditionalExpression.ts, 17, 1))
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 18, 14))
2014-11-05 23:47:05 +01:00
// x is assigned in the if false branch, the type is not narrowed
// even though assigned using same type as narrowed expression
return typeof x === "string"
>typeof x === "string" ? (x = "Hello" && x) // string | number : x : string | number
>typeof x === "string" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 18, 14))
2015-04-13 21:36:11 +02:00
>"string" : string
2014-11-05 23:47:05 +01:00
? (x = "Hello" && x) // string | number
>(x = "Hello" && x) : string | number
>x = "Hello" && x : string | number
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 18, 14))
2014-11-05 23:47:05 +01:00
>"Hello" && x : string | number
2015-04-13 21:36:11 +02:00
>"Hello" : string
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 18, 14))
2014-11-05 23:47:05 +01:00
: x; // string | number
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 18, 14))
2014-11-05 23:47:05 +01:00
}
function foo4(x: number | string) {
2015-04-13 23:01:57 +02:00
>foo4 : (x: string | number) => string | number, Symbol(foo4, Decl(typeGuardsInConditionalExpression.ts, 24, 1))
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 25, 14))
2014-11-05 23:47:05 +01:00
// false branch updates the variable - so here it is not number
// even though assigned using same type as narrowed expression
return typeof x === "string"
>typeof x === "string" ? x // string | number : (x = 10 && x) : string | number
>typeof x === "string" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 25, 14))
2015-04-13 21:36:11 +02:00
>"string" : string
2014-11-05 23:47:05 +01:00
? x // string | number
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 25, 14))
2014-11-05 23:47:05 +01:00
: (x = 10 && x); // string | number
>(x = 10 && x) : string | number
>x = 10 && x : string | number
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 25, 14))
2014-11-05 23:47:05 +01:00
>10 && x : string | number
2015-04-13 21:36:11 +02:00
>10 : number
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 25, 14))
2014-11-05 23:47:05 +01:00
}
function foo5(x: number | string) {
2015-04-13 23:01:57 +02:00
>foo5 : (x: string | number) => string | number, Symbol(foo5, Decl(typeGuardsInConditionalExpression.ts, 31, 1))
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 32, 14))
2014-11-05 23:47:05 +01:00
// false branch updates the variable - so here it is not number
return typeof x === "string"
>typeof x === "string" ? x // string | number : (x = "hello" && x) : string | number
>typeof x === "string" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 32, 14))
2015-04-13 21:36:11 +02:00
>"string" : string
2014-11-05 23:47:05 +01:00
? x // string | number
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 32, 14))
2014-11-05 23:47:05 +01:00
: (x = "hello" && x); // string | number
>(x = "hello" && x) : string | number
>x = "hello" && x : string | number
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 32, 14))
2014-11-05 23:47:05 +01:00
>"hello" && x : string | number
2015-04-13 21:36:11 +02:00
>"hello" : string
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 32, 14))
2014-11-05 23:47:05 +01:00
}
function foo6(x: number | string) {
2015-04-13 23:01:57 +02:00
>foo6 : (x: string | number) => string | number, Symbol(foo6, Decl(typeGuardsInConditionalExpression.ts, 37, 1))
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14))
2014-11-05 23:47:05 +01:00
// Modify in both branches
return typeof x === "string"
>typeof x === "string" ? (x = 10 && x) // string | number : (x = "hello" && x) : string | number
>typeof x === "string" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14))
2015-04-13 21:36:11 +02:00
>"string" : string
2014-11-05 23:47:05 +01:00
? (x = 10 && x) // string | number
>(x = 10 && x) : string | number
>x = 10 && x : string | number
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14))
2014-11-05 23:47:05 +01:00
>10 && x : string | number
2015-04-13 21:36:11 +02:00
>10 : number
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14))
2014-11-05 23:47:05 +01:00
: (x = "hello" && x); // string | number
>(x = "hello" && x) : string | number
>x = "hello" && x : string | number
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14))
2014-11-05 23:47:05 +01:00
>"hello" && x : string | number
2015-04-13 21:36:11 +02:00
>"hello" : string
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 38, 14))
2014-11-05 23:47:05 +01:00
}
function foo7(x: number | string | boolean) {
2015-04-13 23:01:57 +02:00
>foo7 : (x: string | number | boolean) => boolean, Symbol(foo7, Decl(typeGuardsInConditionalExpression.ts, 43, 1))
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14))
2014-11-05 23:47:05 +01:00
return typeof x === "string"
>typeof x === "string" ? x === "hello" // string : typeof x === "boolean" ? x // boolean : x == 10 : boolean
>typeof x === "string" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14))
2015-04-13 21:36:11 +02:00
>"string" : string
2014-11-05 23:47:05 +01:00
? x === "hello" // string
>x === "hello" : boolean
2015-04-13 23:01:57 +02:00
>x : string, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14))
2015-04-13 21:36:11 +02:00
>"hello" : string
2014-11-05 23:47:05 +01:00
: typeof x === "boolean"
>typeof x === "boolean" ? x // boolean : x == 10 : boolean
>typeof x === "boolean" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14))
2015-04-13 21:36:11 +02:00
>"boolean" : string
2014-11-05 23:47:05 +01:00
? x // boolean
2015-04-13 23:01:57 +02:00
>x : boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14))
2014-11-05 23:47:05 +01:00
: x == 10; // number
>x == 10 : boolean
2015-04-13 23:01:57 +02:00
>x : number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 44, 14))
2015-04-13 21:36:11 +02:00
>10 : number
2014-11-05 23:47:05 +01:00
}
function foo8(x: number | string | boolean) {
2015-04-13 23:01:57 +02:00
>foo8 : (x: string | number | boolean) => boolean, Symbol(foo8, Decl(typeGuardsInConditionalExpression.ts, 50, 1))
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14))
2014-11-05 23:47:05 +01:00
var b: number | boolean;
2015-04-13 23:01:57 +02:00
>b : number | boolean, Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 52, 7))
2014-11-05 23:47:05 +01:00
return typeof x === "string"
>typeof x === "string" ? x === "hello" : ((b = x) && // number | boolean (typeof x === "boolean" ? x // boolean : x == 10)) : boolean
>typeof x === "string" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14))
2015-04-13 21:36:11 +02:00
>"string" : string
2014-11-05 23:47:05 +01:00
? x === "hello"
>x === "hello" : boolean
2015-04-13 23:01:57 +02:00
>x : string, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14))
2015-04-13 21:36:11 +02:00
>"hello" : string
2014-11-05 23:47:05 +01:00
: ((b = x) && // number | boolean
>((b = x) && // number | boolean (typeof x === "boolean" ? x // boolean : x == 10)) : boolean
>(b = x) && // number | boolean (typeof x === "boolean" ? x // boolean : x == 10) : boolean
>(b = x) : number | boolean
>b = x : number | boolean
2015-04-13 23:01:57 +02:00
>b : number | boolean, Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 52, 7))
>x : number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14))
2014-11-05 23:47:05 +01:00
(typeof x === "boolean"
>(typeof x === "boolean" ? x // boolean : x == 10) : boolean
>typeof x === "boolean" ? x // boolean : x == 10 : boolean
>typeof x === "boolean" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14))
2015-04-13 21:36:11 +02:00
>"boolean" : string
2014-11-05 23:47:05 +01:00
? x // boolean
2015-04-13 23:01:57 +02:00
>x : boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14))
2014-11-05 23:47:05 +01:00
: x == 10)); // number
>x == 10 : boolean
2015-04-13 23:01:57 +02:00
>x : number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 51, 14))
2015-04-13 21:36:11 +02:00
>10 : number
2014-11-05 23:47:05 +01:00
}
function foo9(x: number | string) {
2015-04-13 23:01:57 +02:00
>foo9 : (x: string | number) => boolean, Symbol(foo9, Decl(typeGuardsInConditionalExpression.ts, 59, 1))
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 60, 14))
2014-11-05 23:47:05 +01:00
var y = 10;
2015-04-13 23:01:57 +02:00
>y : number, Symbol(y, Decl(typeGuardsInConditionalExpression.ts, 61, 7))
2015-04-13 21:36:11 +02:00
>10 : number
2014-11-05 23:47:05 +01:00
// usage of x or assignment to separate variable shouldn't cause narrowing of type to stop
return typeof x === "string"
>typeof x === "string" ? ((y = x.length) && x === "hello") // string : x === 10 : boolean
>typeof x === "string" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : string | number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 60, 14))
2015-04-13 21:36:11 +02:00
>"string" : string
2014-11-05 23:47:05 +01:00
? ((y = x.length) && x === "hello") // string
>((y = x.length) && x === "hello") : boolean
>(y = x.length) && x === "hello" : boolean
>(y = x.length) : number
>y = x.length : number
2015-04-13 23:01:57 +02:00
>y : number, Symbol(y, Decl(typeGuardsInConditionalExpression.ts, 61, 7))
>x.length : number, Symbol(String.length, Decl(lib.d.ts, 414, 19))
>x : string, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 60, 14))
>length : number, Symbol(String.length, Decl(lib.d.ts, 414, 19))
2014-11-05 23:47:05 +01:00
>x === "hello" : boolean
2015-04-13 23:01:57 +02:00
>x : string, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 60, 14))
2015-04-13 21:36:11 +02:00
>"hello" : string
2014-11-05 23:47:05 +01:00
: x === 10; // number
>x === 10 : boolean
2015-04-13 23:01:57 +02:00
>x : number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 60, 14))
2015-04-13 21:36:11 +02:00
>10 : number
2014-11-05 23:47:05 +01:00
}
function foo10(x: number | string | boolean) {
2015-04-13 23:01:57 +02:00
>foo10 : (x: string | number | boolean) => string, Symbol(foo10, Decl(typeGuardsInConditionalExpression.ts, 66, 1))
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15))
2014-11-05 23:47:05 +01:00
// Mixing typeguards
var b: boolean | number;
2015-04-13 23:01:57 +02:00
>b : number | boolean, Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 69, 7))
2014-11-05 23:47:05 +01:00
return typeof x === "string"
>typeof x === "string" ? x // string : ((b = x) // x is number | boolean && typeof x === "number" && x.toString()) : string
>typeof x === "string" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15))
2015-04-13 21:36:11 +02:00
>"string" : string
2014-11-05 23:47:05 +01:00
? x // string
2015-04-13 23:01:57 +02:00
>x : string, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15))
2014-11-05 23:47:05 +01:00
: ((b = x) // x is number | boolean
>((b = x) // x is number | boolean && typeof x === "number" && x.toString()) : string
>(b = x) // x is number | boolean && typeof x === "number" && x.toString() : string
>(b = x) // x is number | boolean && typeof x === "number" : boolean
>(b = x) : number | boolean
>b = x : number | boolean
2015-04-13 23:01:57 +02:00
>b : number | boolean, Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 69, 7))
>x : number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15))
2014-11-05 23:47:05 +01:00
&& typeof x === "number"
>typeof x === "number" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15))
2015-04-13 21:36:11 +02:00
>"number" : string
2014-11-05 23:47:05 +01:00
&& x.toString()); // x is number
>x.toString() : string
2015-04-13 23:01:57 +02:00
>x.toString : (radix?: number) => string, Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
>x : number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 67, 15))
>toString : (radix?: number) => string, Symbol(Number.toString, Decl(lib.d.ts, 458, 18))
2014-11-05 23:47:05 +01:00
}
function foo11(x: number | string | boolean) {
2015-04-13 23:01:57 +02:00
>foo11 : (x: string | number | boolean) => string | number | boolean, Symbol(foo11, Decl(typeGuardsInConditionalExpression.ts, 75, 1))
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15))
2014-11-05 23:47:05 +01:00
// Mixing typeguards
// Assigning value to x deep inside another guard stops narrowing of type too
var b: number | boolean | string;
2015-04-13 23:01:57 +02:00
>b : string | number | boolean, Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 79, 7))
2014-11-05 23:47:05 +01:00
return typeof x === "string"
>typeof x === "string" ? x // number | boolean | string - changed in the false branch : ((b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) // assignment to x && x) : string | number | boolean
>typeof x === "string" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15))
2015-04-13 21:36:11 +02:00
>"string" : string
2014-11-05 23:47:05 +01:00
? x // number | boolean | string - changed in the false branch
2015-04-13 23:01:57 +02:00
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15))
2014-11-05 23:47:05 +01:00
: ((b = x) // x is number | boolean | string - because the assignment changed it
>((b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) // assignment to x && x) : string | number | boolean
>(b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) // assignment to x && x : string | number | boolean
>(b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" && (x = 10) : number
>(b = x) // x is number | boolean | string - because the assignment changed it && typeof x === "number" : boolean
>(b = x) : string | number | boolean
>b = x : string | number | boolean
2015-04-13 23:01:57 +02:00
>b : string | number | boolean, Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 79, 7))
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15))
2014-11-05 23:47:05 +01:00
&& typeof x === "number"
>typeof x === "number" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15))
2015-04-13 21:36:11 +02:00
>"number" : string
2014-11-05 23:47:05 +01:00
&& (x = 10) // assignment to x
>(x = 10) : number
>x = 10 : number
2015-04-13 23:01:57 +02:00
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15))
2015-04-13 21:36:11 +02:00
>10 : number
2014-11-05 23:47:05 +01:00
&& x); // x is number | boolean | string
2015-04-13 23:01:57 +02:00
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 76, 15))
2014-11-05 23:47:05 +01:00
}
function foo12(x: number | string | boolean) {
2015-04-13 23:01:57 +02:00
>foo12 : (x: string | number | boolean) => number, Symbol(foo12, Decl(typeGuardsInConditionalExpression.ts, 86, 1))
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15))
2014-11-05 23:47:05 +01:00
// Mixing typeguards
// Assigning value to x in outer guard shouldn't stop narrowing in the inner expression
var b: number | boolean | string;
2015-04-13 23:01:57 +02:00
>b : string | number | boolean, Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 90, 7))
2014-11-05 23:47:05 +01:00
return typeof x === "string"
>typeof x === "string" ? (x = 10 && x.toString().length) // number | boolean | string - changed here : ((b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" && x) : number
>typeof x === "string" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15))
2015-04-13 21:36:11 +02:00
>"string" : string
2014-11-05 23:47:05 +01:00
? (x = 10 && x.toString().length) // number | boolean | string - changed here
>(x = 10 && x.toString().length) : number
>x = 10 && x.toString().length : number
2015-04-13 23:01:57 +02:00
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15))
2014-11-05 23:47:05 +01:00
>10 && x.toString().length : number
2015-04-13 21:36:11 +02:00
>10 : number
2015-04-13 23:01:57 +02:00
>x.toString().length : number, Symbol(String.length, Decl(lib.d.ts, 414, 19))
2014-11-05 23:47:05 +01:00
>x.toString() : string
2015-04-13 23:01:57 +02:00
>x.toString : () => string, Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26))
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15))
>toString : () => string, Symbol(toString, Decl(lib.d.ts, 277, 18), Decl(lib.d.ts, 458, 18), Decl(lib.d.ts, 96, 26))
>length : number, Symbol(String.length, Decl(lib.d.ts, 414, 19))
2014-11-05 23:47:05 +01:00
: ((b = x) // x is number | boolean | string - changed in true branch
>((b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" && x) : number
>(b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" && x : number
>(b = x) // x is number | boolean | string - changed in true branch && typeof x === "number" : boolean
>(b = x) : string | number | boolean
>b = x : string | number | boolean
2015-04-13 23:01:57 +02:00
>b : string | number | boolean, Symbol(b, Decl(typeGuardsInConditionalExpression.ts, 90, 7))
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15))
2014-11-05 23:47:05 +01:00
&& typeof x === "number"
>typeof x === "number" : boolean
>typeof x : string
2015-04-13 23:01:57 +02:00
>x : string | number | boolean, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15))
2015-04-13 21:36:11 +02:00
>"number" : string
2014-11-05 23:47:05 +01:00
&& x); // x is number
2015-04-13 23:01:57 +02:00
>x : number, Symbol(x, Decl(typeGuardsInConditionalExpression.ts, 87, 15))
2014-11-05 23:47:05 +01:00
}