1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
=== tests/cases/compiler/widenedTypes.ts ===
null instanceof (() => { });
>null instanceof (() => { }) : boolean
>null : null
>(() => { }) : () => void
>() => { } : () => void
({}) instanceof null; // Ok because null is a subtype of function
>({}) instanceof null : boolean
>({}) : {}
>{} : {}
>null : null
null in {};
>null in {} : boolean
>null : null
>{} : {}
"" in null;
>"" in null : boolean
>"" : ""
>null : null
for (var a in null) { }
>a : string
>null : null
var t = [3, (3, null)];
>t : number[]
>[3, (3, null)] : number[]
>3 : 3
>(3, null) : null
>3, null : null
>3 : 3
>null : null
t[3] = "";
>t[3] = "" : ""
>t[3] : number
>t : number[]
>3 : 3
>"" : ""
var x: typeof undefined = 3;
>x : any
>undefined : undefined
>3 : 3
x = 3;
>x = 3 : 3
>x : any
>3 : 3
var y;
>y : any
var u = [3, (y = null)];
>u : number[]
>[3, (y = null)] : number[]
>3 : 3
>(y = null) : null
>y = null : null
>y : any
>null : null
u[3] = "";
>u[3] = "" : ""
>u[3] : number
>u : number[]
>3 : 3
>"" : ""
var ob: { x: typeof undefined } = { x: "" };
>ob : { x: typeof undefined; }
>x : any
>undefined : undefined
>{ x: "" } : { x: string; }
>x : string
>"" : ""
// Highlights the difference between array literals and object literals
var arr: string[] = [3, null]; // not assignable because null is not widened. BCT is {}
>arr : string[]
>[3, null] : number[]
>3 : 3
>null : null
var obj: { [x: string]: string; } = { x: 3, y: null }; // assignable because null is widened, and therefore BCT is any
>obj : { [x: string]: string; }
>x : string
>{ x: 3, y: null } : { x: number; y: null; }
>x : number
>3 : 3
>y : null
>null : null
|