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
|
//@target: ES6
class A {
constructor(
public publicProp: string,
private privateProp: string,
protected protectedProp: string,
) {}
get getter(): number {
return 1;
}
set setter(_v: number) {}
method() {
const { ...rest1 } = this;
const { ...rest2 } = this as A;
const { publicProp: _1, ...rest3 } = this;
const { publicProp: _2, ...rest4 } = this as A;
rest1.publicProp;
rest2.publicProp;
rest3.publicProp;
rest4.publicProp;
rest1.privateProp;
rest2.privateProp;
rest3.privateProp;
rest4.privateProp;
rest1.protectedProp;
rest2.protectedProp;
rest3.protectedProp;
rest4.protectedProp;
rest1.getter;
rest2.getter;
rest3.getter;
rest4.getter;
rest1.setter;
rest2.setter;
rest3.setter;
rest4.setter;
rest1.method;
rest2.method;
rest3.method;
rest4.method;
}
}
function destructure<T extends A>(x: T) {
const { ...rest1 } = x;
const { ...rest2 } = x as A;
const { publicProp: _1, ...rest3 } = x;
const { publicProp: _2, ...rest4 } = x as A;
rest1.publicProp;
rest2.publicProp;
rest3.publicProp;
rest4.publicProp;
rest1.privateProp;
rest2.privateProp;
rest3.privateProp;
rest4.privateProp;
rest1.protectedProp;
rest2.protectedProp;
rest3.protectedProp;
rest4.protectedProp;
rest1.getter;
rest2.getter;
rest3.getter;
rest4.getter;
rest1.setter;
rest2.setter;
rest3.setter;
rest4.setter;
rest1.method;
rest2.method;
rest3.method;
rest4.method;
}
|