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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts ===
// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left.
// An expression of type S is considered assignable to an assignment target V if one of the following is true
// V is an object assignment pattern and, for each assignment property P in V,
// S is the type Any, or
var { a1 }: any = undefined;
>a1 : any
>undefined : undefined
var { a2 }: any = {};
>a2 : any
>{} : {}
// V is an object assignment pattern and, for each assignment property P in V,
// S has an apparent property with the property name specified in
// P of a type that is assignable to the target given in P, or
var { b1, } = { b1:1, };
>b1 : number
>{ b1:1, } : { b1: number; }
>b1 : number
>1 : 1
var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } };
>b2 : any
>b21 : string
>{ b21: "string" } : { b21: string; }
>b21 : string
>"string" : "string"
>{ b2: { b21: "world" } } : { b2?: { b21: string; }; }
>b2 : { b21: string; }
>{ b21: "world" } : { b21: string; }
>b21 : string
>"world" : "world"
var {1: b3} = { 1: "string" };
>b3 : string
>{ 1: "string" } : { 1: string; }
>1 : string
>"string" : "string"
var {b4 = 1}: any = { b4: 100000 };
>b4 : any
>1 : 1
>{ b4: 100000 } : { b4: number; }
>b4 : number
>100000 : 100000
var {b5: { b52 } } = { b5: { b52 } };
>b5 : any
>b52 : any
>{ b5: { b52 } } : { b5: { b52: any; }; }
>b5 : { b52: any; }
>{ b52 } : { b52: any; }
>b52 : any
// V is an object assignment pattern and, for each assignment property P in V,
// P specifies a numeric property name and S has a numeric index signature
// of a type that is assignable to the target given in P, or
interface F {
[idx: number]: boolean;
>idx : number
}
function foo(): F {
>foo : () => F
return {
>{ 1: true } : { 1: true; }
1: true
>1 : true
>true : true
};
}
function bar(): F {
>bar : () => F
return {
>{ 2: true } : { 2: true; }
2: true
>2 : true
>true : true
};
}
var {1: c0} = foo();
>c0 : boolean
>foo() : F
>foo : () => F
var {1: c1} = bar();
>c1 : boolean
>bar() : F
>bar : () => F
// V is an object assignment pattern and, for each assignment property P in V,
// S has a string index signature of a type that is assignable to the target given in P
interface F1 {
[str: string]: number;
>str : string
}
function foo1(): F1 {
>foo1 : () => F1
return {
>{ "prop1": 2 } : { "prop1": number; }
"prop1": 2
>"prop1" : number
>2 : 2
}
}
var {"prop1": d1} = foo1();
>d1 : number
>foo1() : F1
>foo1 : () => F1
var {"prop2": d1} = foo1();
>d1 : number
>foo1() : F1
>foo1 : () => F1
|