TypeScript/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types

226 lines
10 KiB
Plaintext
Raw Normal View History

2014-08-15 23:33:16 +02:00
=== tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithIdenticalBCT.ts ===
//Cond ? Expr1 : Expr2, Expr1 and Expr2 have identical best common type
class X { propertyX: any; propertyX1: number; propertyX2: string };
2015-04-13 23:01:57 +02:00
>X : X, Symbol(X, Decl(conditionalOperatorWithIdenticalBCT.ts, 0, 0))
>propertyX : any, Symbol(propertyX, Decl(conditionalOperatorWithIdenticalBCT.ts, 1, 9))
>propertyX1 : number, Symbol(propertyX1, Decl(conditionalOperatorWithIdenticalBCT.ts, 1, 25))
>propertyX2 : string, Symbol(propertyX2, Decl(conditionalOperatorWithIdenticalBCT.ts, 1, 45))
2014-08-15 23:33:16 +02:00
class A extends X { propertyA: number };
2015-04-13 23:01:57 +02:00
>A : A, Symbol(A, Decl(conditionalOperatorWithIdenticalBCT.ts, 1, 67))
>X : X, Symbol(X, Decl(conditionalOperatorWithIdenticalBCT.ts, 0, 0))
>propertyA : number, Symbol(propertyA, Decl(conditionalOperatorWithIdenticalBCT.ts, 2, 19))
2014-08-15 23:33:16 +02:00
class B extends X { propertyB: string };
2015-04-13 23:01:57 +02:00
>B : B, Symbol(B, Decl(conditionalOperatorWithIdenticalBCT.ts, 2, 40))
>X : X, Symbol(X, Decl(conditionalOperatorWithIdenticalBCT.ts, 0, 0))
>propertyB : string, Symbol(propertyB, Decl(conditionalOperatorWithIdenticalBCT.ts, 3, 19))
2014-08-15 23:33:16 +02:00
var x: X;
2015-04-13 23:01:57 +02:00
>x : X, Symbol(x, Decl(conditionalOperatorWithIdenticalBCT.ts, 5, 3))
>X : X, Symbol(X, Decl(conditionalOperatorWithIdenticalBCT.ts, 0, 0))
2014-08-15 23:33:16 +02:00
var a: A;
2015-04-13 23:01:57 +02:00
>a : A, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 6, 3))
>A : A, Symbol(A, Decl(conditionalOperatorWithIdenticalBCT.ts, 1, 67))
2014-08-15 23:33:16 +02:00
var b: B;
2015-04-13 23:01:57 +02:00
>b : B, Symbol(b, Decl(conditionalOperatorWithIdenticalBCT.ts, 7, 3))
>B : B, Symbol(B, Decl(conditionalOperatorWithIdenticalBCT.ts, 2, 40))
2014-08-15 23:33:16 +02:00
//Cond ? Expr1 : Expr2, Expr1 is supertype
//Be Not contextually typed
true ? x : a;
>true ? x : a : X
2015-04-13 21:36:11 +02:00
>true : boolean
2015-04-13 23:01:57 +02:00
>x : X, Symbol(x, Decl(conditionalOperatorWithIdenticalBCT.ts, 5, 3))
>a : A, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 6, 3))
2014-08-15 23:33:16 +02:00
var result1 = true ? x : a;
2015-04-13 23:01:57 +02:00
>result1 : X, Symbol(result1, Decl(conditionalOperatorWithIdenticalBCT.ts, 12, 3))
2014-08-15 23:33:16 +02:00
>true ? x : a : X
2015-04-13 21:36:11 +02:00
>true : boolean
2015-04-13 23:01:57 +02:00
>x : X, Symbol(x, Decl(conditionalOperatorWithIdenticalBCT.ts, 5, 3))
>a : A, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 6, 3))
2014-08-15 23:33:16 +02:00
//Expr1 and Expr2 are literals
true ? {} : 1;
>true ? {} : 1 : {}
2015-04-13 21:36:11 +02:00
>true : boolean
2014-08-15 23:33:16 +02:00
>{} : {}
2015-04-13 21:36:11 +02:00
>1 : number
2014-08-15 23:33:16 +02:00
true ? { a: 1 } : { a: 2, b: 'string' };
>true ? { a: 1 } : { a: 2, b: 'string' } : { a: number; }
2015-04-13 21:36:11 +02:00
>true : boolean
2014-08-15 23:33:16 +02:00
>{ a: 1 } : { a: number; }
2015-04-13 23:01:57 +02:00
>a : number, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 16, 8))
2015-04-13 21:36:11 +02:00
>1 : number
2014-08-15 23:33:16 +02:00
>{ a: 2, b: 'string' } : { a: number; b: string; }
2015-04-13 23:01:57 +02:00
>a : number, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 16, 19))
2015-04-13 21:36:11 +02:00
>2 : number
2015-04-13 23:01:57 +02:00
>b : string, Symbol(b, Decl(conditionalOperatorWithIdenticalBCT.ts, 16, 25))
2015-04-13 21:36:11 +02:00
>'string' : string
2014-08-15 23:33:16 +02:00
var result2 = true ? {} : 1;
2015-04-13 23:01:57 +02:00
>result2 : {}, Symbol(result2, Decl(conditionalOperatorWithIdenticalBCT.ts, 17, 3))
2014-08-15 23:33:16 +02:00
>true ? {} : 1 : {}
2015-04-13 21:36:11 +02:00
>true : boolean
2014-08-15 23:33:16 +02:00
>{} : {}
2015-04-13 21:36:11 +02:00
>1 : number
2014-08-15 23:33:16 +02:00
var result3 = true ? { a: 1 } : { a: 2, b: 'string' };
2015-04-13 23:01:57 +02:00
>result3 : { a: number; }, Symbol(result3, Decl(conditionalOperatorWithIdenticalBCT.ts, 18, 3))
2014-08-15 23:33:16 +02:00
>true ? { a: 1 } : { a: 2, b: 'string' } : { a: number; }
2015-04-13 21:36:11 +02:00
>true : boolean
2014-08-15 23:33:16 +02:00
>{ a: 1 } : { a: number; }
2015-04-13 23:01:57 +02:00
>a : number, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 18, 22))
2015-04-13 21:36:11 +02:00
>1 : number
2014-08-15 23:33:16 +02:00
>{ a: 2, b: 'string' } : { a: number; b: string; }
2015-04-13 23:01:57 +02:00
>a : number, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 18, 33))
2015-04-13 21:36:11 +02:00
>2 : number
2015-04-13 23:01:57 +02:00
>b : string, Symbol(b, Decl(conditionalOperatorWithIdenticalBCT.ts, 18, 39))
2015-04-13 21:36:11 +02:00
>'string' : string
2014-08-15 23:33:16 +02:00
//Contextually typed
var resultIsX1: X = true ? x : a;
2015-04-13 23:01:57 +02:00
>resultIsX1 : X, Symbol(resultIsX1, Decl(conditionalOperatorWithIdenticalBCT.ts, 21, 3))
>X : X, Symbol(X, Decl(conditionalOperatorWithIdenticalBCT.ts, 0, 0))
2014-08-15 23:33:16 +02:00
>true ? x : a : X
2015-04-13 21:36:11 +02:00
>true : boolean
2015-04-13 23:01:57 +02:00
>x : X, Symbol(x, Decl(conditionalOperatorWithIdenticalBCT.ts, 5, 3))
>a : A, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 6, 3))
2014-08-15 23:33:16 +02:00
var result4: (t: A) => any = true ? (m) => m.propertyX : (n) => n.propertyA;
2015-04-13 23:01:57 +02:00
>result4 : (t: A) => any, Symbol(result4, Decl(conditionalOperatorWithIdenticalBCT.ts, 22, 3))
>t : A, Symbol(t, Decl(conditionalOperatorWithIdenticalBCT.ts, 22, 14))
>A : A, Symbol(A, Decl(conditionalOperatorWithIdenticalBCT.ts, 1, 67))
2014-10-11 02:01:28 +02:00
>true ? (m) => m.propertyX : (n) => n.propertyA : (m: A) => any
2015-04-13 21:36:11 +02:00
>true : boolean
2014-08-15 23:33:16 +02:00
>(m) => m.propertyX : (m: A) => any
2015-04-13 23:01:57 +02:00
>m : A, Symbol(m, Decl(conditionalOperatorWithIdenticalBCT.ts, 22, 37))
>m.propertyX : any, Symbol(X.propertyX, Decl(conditionalOperatorWithIdenticalBCT.ts, 1, 9))
>m : A, Symbol(m, Decl(conditionalOperatorWithIdenticalBCT.ts, 22, 37))
>propertyX : any, Symbol(X.propertyX, Decl(conditionalOperatorWithIdenticalBCT.ts, 1, 9))
2014-08-15 23:33:16 +02:00
>(n) => n.propertyA : (n: A) => number
2015-04-13 23:01:57 +02:00
>n : A, Symbol(n, Decl(conditionalOperatorWithIdenticalBCT.ts, 22, 58))
>n.propertyA : number, Symbol(A.propertyA, Decl(conditionalOperatorWithIdenticalBCT.ts, 2, 19))
>n : A, Symbol(n, Decl(conditionalOperatorWithIdenticalBCT.ts, 22, 58))
>propertyA : number, Symbol(A.propertyA, Decl(conditionalOperatorWithIdenticalBCT.ts, 2, 19))
2014-08-15 23:33:16 +02:00
//Cond ? Expr1 : Expr2, Expr2 is supertype
//Be Not contextually typed
true ? a : x;
>true ? a : x : X
2015-04-13 21:36:11 +02:00
>true : boolean
2015-04-13 23:01:57 +02:00
>a : A, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 6, 3))
>x : X, Symbol(x, Decl(conditionalOperatorWithIdenticalBCT.ts, 5, 3))
2014-08-15 23:33:16 +02:00
var result5 = true ? a : x;
2015-04-13 23:01:57 +02:00
>result5 : X, Symbol(result5, Decl(conditionalOperatorWithIdenticalBCT.ts, 27, 3))
2014-08-15 23:33:16 +02:00
>true ? a : x : X
2015-04-13 21:36:11 +02:00
>true : boolean
2015-04-13 23:01:57 +02:00
>a : A, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 6, 3))
>x : X, Symbol(x, Decl(conditionalOperatorWithIdenticalBCT.ts, 5, 3))
2014-08-15 23:33:16 +02:00
//Expr1 and Expr2 are literals
true ? 1 : {};
>true ? 1 : {} : {}
2015-04-13 21:36:11 +02:00
>true : boolean
>1 : number
2014-08-15 23:33:16 +02:00
>{} : {}
true ? { a: 2, b: 'string' } : { a: 1 };
>true ? { a: 2, b: 'string' } : { a: 1 } : { a: number; }
2015-04-13 21:36:11 +02:00
>true : boolean
2014-08-15 23:33:16 +02:00
>{ a: 2, b: 'string' } : { a: number; b: string; }
2015-04-13 23:01:57 +02:00
>a : number, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 31, 8))
2015-04-13 21:36:11 +02:00
>2 : number
2015-04-13 23:01:57 +02:00
>b : string, Symbol(b, Decl(conditionalOperatorWithIdenticalBCT.ts, 31, 14))
2015-04-13 21:36:11 +02:00
>'string' : string
2014-08-15 23:33:16 +02:00
>{ a: 1 } : { a: number; }
2015-04-13 23:01:57 +02:00
>a : number, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 31, 32))
2015-04-13 21:36:11 +02:00
>1 : number
2014-08-15 23:33:16 +02:00
var result6 = true ? 1 : {};
2015-04-13 23:01:57 +02:00
>result6 : {}, Symbol(result6, Decl(conditionalOperatorWithIdenticalBCT.ts, 32, 3))
2014-08-15 23:33:16 +02:00
>true ? 1 : {} : {}
2015-04-13 21:36:11 +02:00
>true : boolean
>1 : number
2014-08-15 23:33:16 +02:00
>{} : {}
var result7 = true ? { a: 2, b: 'string' } : { a: 1 };
2015-04-13 23:01:57 +02:00
>result7 : { a: number; }, Symbol(result7, Decl(conditionalOperatorWithIdenticalBCT.ts, 33, 3))
2014-08-15 23:33:16 +02:00
>true ? { a: 2, b: 'string' } : { a: 1 } : { a: number; }
2015-04-13 21:36:11 +02:00
>true : boolean
2014-08-15 23:33:16 +02:00
>{ a: 2, b: 'string' } : { a: number; b: string; }
2015-04-13 23:01:57 +02:00
>a : number, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 33, 22))
2015-04-13 21:36:11 +02:00
>2 : number
2015-04-13 23:01:57 +02:00
>b : string, Symbol(b, Decl(conditionalOperatorWithIdenticalBCT.ts, 33, 28))
2015-04-13 21:36:11 +02:00
>'string' : string
2014-08-15 23:33:16 +02:00
>{ a: 1 } : { a: number; }
2015-04-13 23:01:57 +02:00
>a : number, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 33, 46))
2015-04-13 21:36:11 +02:00
>1 : number
2014-08-15 23:33:16 +02:00
//Contextually typed
var resultIsX2: X = true ? x : a;
2015-04-13 23:01:57 +02:00
>resultIsX2 : X, Symbol(resultIsX2, Decl(conditionalOperatorWithIdenticalBCT.ts, 36, 3))
>X : X, Symbol(X, Decl(conditionalOperatorWithIdenticalBCT.ts, 0, 0))
2014-08-15 23:33:16 +02:00
>true ? x : a : X
2015-04-13 21:36:11 +02:00
>true : boolean
2015-04-13 23:01:57 +02:00
>x : X, Symbol(x, Decl(conditionalOperatorWithIdenticalBCT.ts, 5, 3))
>a : A, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 6, 3))
2014-08-15 23:33:16 +02:00
var result8: (t: A) => any = true ? (m) => m.propertyA : (n) => n.propertyX;
2015-04-13 23:01:57 +02:00
>result8 : (t: A) => any, Symbol(result8, Decl(conditionalOperatorWithIdenticalBCT.ts, 37, 3))
>t : A, Symbol(t, Decl(conditionalOperatorWithIdenticalBCT.ts, 37, 14))
>A : A, Symbol(A, Decl(conditionalOperatorWithIdenticalBCT.ts, 1, 67))
2014-10-11 02:01:28 +02:00
>true ? (m) => m.propertyA : (n) => n.propertyX : (n: A) => any
2015-04-13 21:36:11 +02:00
>true : boolean
2014-08-15 23:33:16 +02:00
>(m) => m.propertyA : (m: A) => number
2015-04-13 23:01:57 +02:00
>m : A, Symbol(m, Decl(conditionalOperatorWithIdenticalBCT.ts, 37, 37))
>m.propertyA : number, Symbol(A.propertyA, Decl(conditionalOperatorWithIdenticalBCT.ts, 2, 19))
>m : A, Symbol(m, Decl(conditionalOperatorWithIdenticalBCT.ts, 37, 37))
>propertyA : number, Symbol(A.propertyA, Decl(conditionalOperatorWithIdenticalBCT.ts, 2, 19))
2014-08-15 23:33:16 +02:00
>(n) => n.propertyX : (n: A) => any
2015-04-13 23:01:57 +02:00
>n : A, Symbol(n, Decl(conditionalOperatorWithIdenticalBCT.ts, 37, 58))
>n.propertyX : any, Symbol(X.propertyX, Decl(conditionalOperatorWithIdenticalBCT.ts, 1, 9))
>n : A, Symbol(n, Decl(conditionalOperatorWithIdenticalBCT.ts, 37, 58))
>propertyX : any, Symbol(X.propertyX, Decl(conditionalOperatorWithIdenticalBCT.ts, 1, 9))
2014-08-15 23:33:16 +02:00
//Result = Cond ? Expr1 : Expr2, Result is supertype
//Contextually typed
var resultIsX3: X = true ? a : b;
2015-04-13 23:01:57 +02:00
>resultIsX3 : X, Symbol(resultIsX3, Decl(conditionalOperatorWithIdenticalBCT.ts, 41, 3))
>X : X, Symbol(X, Decl(conditionalOperatorWithIdenticalBCT.ts, 0, 0))
2014-10-11 02:01:28 +02:00
>true ? a : b : A | B
2015-04-13 21:36:11 +02:00
>true : boolean
2015-04-13 23:01:57 +02:00
>a : A, Symbol(a, Decl(conditionalOperatorWithIdenticalBCT.ts, 6, 3))
>b : B, Symbol(b, Decl(conditionalOperatorWithIdenticalBCT.ts, 7, 3))
2014-08-15 23:33:16 +02:00
var result10: (t: X) => any = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
2015-04-13 23:01:57 +02:00
>result10 : (t: X) => any, Symbol(result10, Decl(conditionalOperatorWithIdenticalBCT.ts, 42, 3))
>t : X, Symbol(t, Decl(conditionalOperatorWithIdenticalBCT.ts, 42, 15))
>X : X, Symbol(X, Decl(conditionalOperatorWithIdenticalBCT.ts, 0, 0))
>true ? (m) => m.propertyX1 : (n) => n.propertyX2 : ((m: X) => number) | ((n: X) => string)
2015-04-13 21:36:11 +02:00
>true : boolean
2014-08-15 23:33:16 +02:00
>(m) => m.propertyX1 : (m: X) => number
2015-04-13 23:01:57 +02:00
>m : X, Symbol(m, Decl(conditionalOperatorWithIdenticalBCT.ts, 42, 38))
>m.propertyX1 : number, Symbol(X.propertyX1, Decl(conditionalOperatorWithIdenticalBCT.ts, 1, 25))
>m : X, Symbol(m, Decl(conditionalOperatorWithIdenticalBCT.ts, 42, 38))
>propertyX1 : number, Symbol(X.propertyX1, Decl(conditionalOperatorWithIdenticalBCT.ts, 1, 25))
2014-08-15 23:33:16 +02:00
>(n) => n.propertyX2 : (n: X) => string
2015-04-13 23:01:57 +02:00
>n : X, Symbol(n, Decl(conditionalOperatorWithIdenticalBCT.ts, 42, 60))
>n.propertyX2 : string, Symbol(X.propertyX2, Decl(conditionalOperatorWithIdenticalBCT.ts, 1, 45))
>n : X, Symbol(n, Decl(conditionalOperatorWithIdenticalBCT.ts, 42, 60))
>propertyX2 : string, Symbol(X.propertyX2, Decl(conditionalOperatorWithIdenticalBCT.ts, 1, 45))
2014-08-15 23:33:16 +02:00
//Expr1 and Expr2 are literals
var result11: any = true ? 1 : 'string';
2015-04-13 23:01:57 +02:00
>result11 : any, Symbol(result11, Decl(conditionalOperatorWithIdenticalBCT.ts, 45, 3))
2014-10-11 02:01:28 +02:00
>true ? 1 : 'string' : string | number
2015-04-13 21:36:11 +02:00
>true : boolean
>1 : number
>'string' : string
2014-08-15 23:33:16 +02:00