TypeScript/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types

134 lines
2.9 KiB
Plaintext
Raw Normal View History

2015-04-17 03:53:16 +02:00
=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.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;
2015-04-17 04:20:08 +02:00
>a1 : any
>undefined : undefined
2015-04-17 03:53:16 +02:00
var { a2 }: any = {};
2015-04-17 04:20:08 +02:00
>a2 : any
2015-04-17 03:53:16 +02:00
>{} : {}
// 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, };
2015-04-17 04:20:08 +02:00
>b1 : number
2015-04-17 03:53:16 +02:00
>{ b1:1, } : { b1: number; }
2015-04-17 04:20:08 +02:00
>b1 : number
2015-04-17 03:53:16 +02:00
>1 : number
var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } };
>b2 : any
2015-04-17 04:20:08 +02:00
>b21 : string
2015-04-17 03:53:16 +02:00
>{ b21: "string" } : { b21: string; }
2015-04-17 04:20:08 +02:00
>b21 : string
2015-04-17 03:53:16 +02:00
>"string" : string
>{ b2: { b21: "world" } } : { b2: { b21: string; }; }
2015-04-17 04:20:08 +02:00
>b2 : { b21: string; }
2015-04-17 03:53:16 +02:00
>{ b21: "world" } : { b21: string; }
2015-04-17 04:20:08 +02:00
>b21 : string
2015-04-17 03:53:16 +02:00
>"world" : string
var {1: b3} = { 1: "string" };
2015-04-17 04:20:08 +02:00
>b3 : string
2015-04-17 03:53:16 +02:00
>{ 1: "string" } : { 1: string; }
>"string" : string
var {b4 = 1}: any = { b4: 100000 };
2015-04-17 04:20:08 +02:00
>b4 : number
2015-04-17 03:53:16 +02:00
>1 : number
>{ b4: 100000 } : { b4: number; }
2015-04-17 04:20:08 +02:00
>b4 : number
2015-04-17 03:53:16 +02:00
>100000 : number
var {b5: { b52 } } = { b5: { b52 } };
>b5 : any
2015-04-17 04:20:08 +02:00
>b52 : any
2015-04-17 03:53:16 +02:00
>{ b5: { b52 } } : { b5: { b52: any; }; }
2015-04-17 04:20:08 +02:00
>b5 : { b52: any; }
2015-04-17 03:53:16 +02:00
>{ b52 } : { b52: any; }
2015-04-17 04:20:08 +02:00
>b52 : any
2015-04-17 03:53:16 +02:00
// 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 {
2015-04-17 04:20:08 +02:00
>F : F
2015-04-17 03:53:16 +02:00
[idx: number]: boolean;
2015-04-17 04:20:08 +02:00
>idx : number
2015-04-17 03:53:16 +02:00
}
function foo(): F {
2015-04-17 04:20:08 +02:00
>foo : () => F
>F : F
2015-04-17 03:53:16 +02:00
return {
>{ 1: true } : { [x: number]: boolean; 1: boolean; }
1: true
>true : boolean
};
}
function bar(): F {
2015-04-17 04:20:08 +02:00
>bar : () => F
>F : F
2015-04-17 03:53:16 +02:00
return {
>{ 2: true } : { [x: number]: boolean; 2: boolean; }
2: true
>true : boolean
};
}
var {1: c0} = foo();
2015-04-17 04:20:08 +02:00
>c0 : boolean
2015-04-17 03:53:16 +02:00
>foo() : F
2015-04-17 04:20:08 +02:00
>foo : () => F
2015-04-17 03:53:16 +02:00
var {1: c1} = bar();
2015-04-17 04:20:08 +02:00
>c1 : boolean
2015-04-17 03:53:16 +02:00
>bar() : F
2015-04-17 04:20:08 +02:00
>bar : () => F
2015-04-17 03:53:16 +02:00
// 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 {
2015-04-17 04:20:08 +02:00
>F1 : F1
2015-04-17 03:53:16 +02:00
[str: string]: number;
2015-04-17 04:20:08 +02:00
>str : string
2015-04-17 03:53:16 +02:00
}
function foo1(): F1 {
2015-04-17 04:20:08 +02:00
>foo1 : () => F1
>F1 : F1
2015-04-17 03:53:16 +02:00
return {
>{ "prop1": 2 } : { [x: string]: number; "prop1": number; }
"prop1": 2
>2 : number
}
}
var {"prop1": d1} = foo1();
2015-04-17 04:20:08 +02:00
>d1 : number
2015-04-17 03:53:16 +02:00
>foo1() : F1
2015-04-17 04:20:08 +02:00
>foo1 : () => F1
2015-04-17 03:53:16 +02:00
var {"prop2": d1} = foo1();
2015-04-17 04:20:08 +02:00
>d1 : number
2015-04-17 03:53:16 +02:00
>foo1() : F1
2015-04-17 04:20:08 +02:00
>foo1 : () => F1
2015-04-17 03:53:16 +02:00