102 lines
4.6 KiB
Plaintext
102 lines
4.6 KiB
Plaintext
=== 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 : Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 5, 5))
|
|
>undefined : Symbol(undefined)
|
|
|
|
var { a2 }: any = {};
|
|
>a2 : Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 6, 5))
|
|
|
|
// 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 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 5))
|
|
>b1 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 15))
|
|
|
|
var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } };
|
|
>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 11))
|
|
>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 21))
|
|
>b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 44))
|
|
>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 50))
|
|
|
|
var {1: b3} = { 1: "string" };
|
|
>b3 : Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 13, 5))
|
|
|
|
var {b4 = 1}: any = { b4: 100000 };
|
|
>b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 5))
|
|
>b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 21))
|
|
|
|
var {b5: { b52 } } = { b5: { b52 } };
|
|
>b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 10))
|
|
>b5 : Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 23))
|
|
>b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 29))
|
|
|
|
// 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 {
|
|
>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38))
|
|
|
|
[idx: number]: boolean;
|
|
>idx : Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 22, 5))
|
|
}
|
|
|
|
function foo(): F {
|
|
>foo : Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1))
|
|
>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38))
|
|
|
|
return {
|
|
1: true
|
|
};
|
|
}
|
|
|
|
function bar(): F {
|
|
>bar : Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1))
|
|
>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38))
|
|
|
|
return {
|
|
2: true
|
|
};
|
|
}
|
|
var {1: c0} = foo();
|
|
>c0 : Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 36, 5))
|
|
>foo : Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1))
|
|
|
|
var {1: c1} = bar();
|
|
>c1 : Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 5))
|
|
>bar : Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1))
|
|
|
|
// 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 {
|
|
>F1 : Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20))
|
|
|
|
[str: string]: number;
|
|
>str : Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 43, 5))
|
|
}
|
|
|
|
function foo1(): F1 {
|
|
>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1))
|
|
>F1 : Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20))
|
|
|
|
return {
|
|
"prop1": 2
|
|
}
|
|
}
|
|
|
|
var {"prop1": d1} = foo1();
|
|
>d1 : Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5))
|
|
>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1))
|
|
|
|
var {"prop2": d1} = foo1();
|
|
>d1 : Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5))
|
|
>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1))
|
|
|