mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Added tests.
This commit is contained in:
parent
cbecae3cf3
commit
b434ee42a8
@ -0,0 +1,68 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(16,24): error TS1005: ',' expected.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(22,26): error TS2339: Property 'x' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(22,35): error TS2339: Property 'y' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(22,43): error TS2339: Property 'y' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(22,52): error TS2339: Property 'z' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,26): error TS2339: Property 'x' does not exist on type 'C2'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,35): error TS2339: Property 'y' does not exist on type 'C2'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,43): error TS2339: Property 'y' does not exist on type 'C2'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(25,52): error TS2339: Property 'z' does not exist on type 'C2'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(27,10): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(28,6): error TS2346: Supplied parameters do not match any signature of call target.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts(28,23): error TS1005: ':' expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters1.ts (12 errors) ====
|
||||
class C1 {
|
||||
constructor(public [x, y, z]: string[]) {
|
||||
}
|
||||
}
|
||||
|
||||
type TupleType1 = [string, number, boolean];
|
||||
|
||||
class C2 {
|
||||
constructor(public [x, y, z]: TupleType1) {
|
||||
}
|
||||
}
|
||||
|
||||
type ObjType1 = { x: number; y: string; z: boolean }
|
||||
|
||||
class C3 {
|
||||
constructor(public { x, y, z }: ObjType1) {
|
||||
~
|
||||
!!! error TS1005: ',' expected.
|
||||
}
|
||||
}
|
||||
|
||||
var c1 = new C1([]);
|
||||
c1 = new C1(["larry", "{curly}", "moe"]);
|
||||
var useC1Properties = c1.x === c1.y && c1.y === c1.z;
|
||||
~
|
||||
!!! error TS2339: Property 'x' does not exist on type 'C1'.
|
||||
~
|
||||
!!! error TS2339: Property 'y' does not exist on type 'C1'.
|
||||
~
|
||||
!!! error TS2339: Property 'y' does not exist on type 'C1'.
|
||||
~
|
||||
!!! error TS2339: Property 'z' does not exist on type 'C1'.
|
||||
|
||||
var c2 = new C2(["10", 10, !!10]);
|
||||
var useC2Properties = c2.x === c2.y && c2.y === c2.z;
|
||||
~
|
||||
!!! error TS2339: Property 'x' does not exist on type 'C2'.
|
||||
~
|
||||
!!! error TS2339: Property 'y' does not exist on type 'C2'.
|
||||
~
|
||||
!!! error TS2339: Property 'y' does not exist on type 'C2'.
|
||||
~
|
||||
!!! error TS2339: Property 'z' does not exist on type 'C2'.
|
||||
|
||||
var c3 = new C3({x: 0, y: "", z: false});
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
c3 = new C3({x: 0, "y", z: true});
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2346: Supplied parameters do not match any signature of call target.
|
||||
~
|
||||
!!! error TS1005: ':' expected.
|
||||
var useC3Properties = c3.x === c3.y && c3.y === c3.z;
|
||||
@ -0,0 +1,53 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(3,59): error TS2339: Property 'b' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(3,83): error TS2339: Property 'c' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(4,18): error TS2339: Property 'a' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(9,21): error TS2339: Property 'a' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(13,21): error TS2339: Property 'b' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(17,21): error TS2339: Property 'c' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts(21,27): error TS2345: Argument of type '[number, undefined, string]' is not assignable to parameter of type '[number, string, boolean]'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters2.ts (7 errors) ====
|
||||
class C1 {
|
||||
constructor(private k: number, private [a, b, c]: [number, string, boolean]) {
|
||||
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
|
||||
~
|
||||
!!! error TS2339: Property 'b' does not exist on type 'C1'.
|
||||
~
|
||||
!!! error TS2339: Property 'c' does not exist on type 'C1'.
|
||||
this.a = a || k;
|
||||
~
|
||||
!!! error TS2339: Property 'a' does not exist on type 'C1'.
|
||||
}
|
||||
}
|
||||
|
||||
public getA() {
|
||||
return this.a
|
||||
~
|
||||
!!! error TS2339: Property 'a' does not exist on type 'C1'.
|
||||
}
|
||||
|
||||
public getB() {
|
||||
return this.b
|
||||
~
|
||||
!!! error TS2339: Property 'b' does not exist on type 'C1'.
|
||||
}
|
||||
|
||||
public getC() {
|
||||
return this.c;
|
||||
~
|
||||
!!! error TS2339: Property 'c' does not exist on type 'C1'.
|
||||
}
|
||||
}
|
||||
|
||||
var x = new C1(undefined, [0, undefined, ""]);
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[number, undefined, string]' is not assignable to parameter of type '[number, string, boolean]'.
|
||||
var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()];
|
||||
|
||||
var y = new C1(10, [0, "", true]);
|
||||
var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()];
|
||||
|
||||
var z = new C1(10, [undefined, "", null]);
|
||||
var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()];
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
//// [destructuringPropertyParameters2.ts]
|
||||
class C1 {
|
||||
constructor(private k: number, private [a, b, c]: [number, string, boolean]) {
|
||||
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
|
||||
this.a = a || k;
|
||||
}
|
||||
}
|
||||
|
||||
public getA() {
|
||||
return this.a
|
||||
}
|
||||
|
||||
public getB() {
|
||||
return this.b
|
||||
}
|
||||
|
||||
public getC() {
|
||||
return this.c;
|
||||
}
|
||||
}
|
||||
|
||||
var x = new C1(undefined, [0, undefined, ""]);
|
||||
var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()];
|
||||
|
||||
var y = new C1(10, [0, "", true]);
|
||||
var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()];
|
||||
|
||||
var z = new C1(10, [undefined, "", null]);
|
||||
var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()];
|
||||
|
||||
|
||||
//// [destructuringPropertyParameters2.js]
|
||||
var C1 = (function () {
|
||||
function C1(k, _a) {
|
||||
var a = _a[0], b = _a[1], c = _a[2];
|
||||
this.k = k;
|
||||
this.[a, b, c] = [a, b, c];
|
||||
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
|
||||
this.a = a || k;
|
||||
}
|
||||
}
|
||||
C1.prototype.getA = function () {
|
||||
return this.a;
|
||||
};
|
||||
C1.prototype.getB = function () {
|
||||
return this.b;
|
||||
};
|
||||
C1.prototype.getC = function () {
|
||||
return this.c;
|
||||
};
|
||||
return C1;
|
||||
})();
|
||||
var x = new C1(undefined, [0, undefined, ""]);
|
||||
var _a = [x.getA(), x.getB(), x.getC()], x_a = _a[0], x_b = _a[1], x_c = _a[2];
|
||||
var y = new C1(10, [0, "", true]);
|
||||
var _b = [y.getA(), y.getB(), y.getC()], y_a = _b[0], y_b = _b[1], y_c = _b[2];
|
||||
var z = new C1(10, [undefined, "", null]);
|
||||
var _c = [z.getA(), z.getB(), z.getC()], z_a = _c[0], z_b = _c[1], z_c = _c[2];
|
||||
@ -0,0 +1,53 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(3,59): error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(3,83): error TS2339: Property 'c' does not exist on type 'C1<T, U, V>'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(4,18): error TS2339: Property 'a' does not exist on type 'C1<T, U, V>'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(9,21): error TS2339: Property 'a' does not exist on type 'C1<T, U, V>'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(13,21): error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts(17,21): error TS2339: Property 'c' does not exist on type 'C1<T, U, V>'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters3.ts (6 errors) ====
|
||||
class C1<T, U, V> {
|
||||
constructor(private k: T, private [a, b, c]: [T,U,V]) {
|
||||
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
|
||||
~
|
||||
!!! error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
|
||||
~
|
||||
!!! error TS2339: Property 'c' does not exist on type 'C1<T, U, V>'.
|
||||
this.a = a || k;
|
||||
~
|
||||
!!! error TS2339: Property 'a' does not exist on type 'C1<T, U, V>'.
|
||||
}
|
||||
}
|
||||
|
||||
public getA() {
|
||||
return this.a
|
||||
~
|
||||
!!! error TS2339: Property 'a' does not exist on type 'C1<T, U, V>'.
|
||||
}
|
||||
|
||||
public getB() {
|
||||
return this.b
|
||||
~
|
||||
!!! error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
|
||||
}
|
||||
|
||||
public getC() {
|
||||
return this.c;
|
||||
~
|
||||
!!! error TS2339: Property 'c' does not exist on type 'C1<T, U, V>'.
|
||||
}
|
||||
}
|
||||
|
||||
var x = new C1(undefined, [0, true, ""]);
|
||||
var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()];
|
||||
|
||||
var y = new C1(10, [0, true, true]);
|
||||
var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()];
|
||||
|
||||
var z = new C1(10, [undefined, "", ""]);
|
||||
var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()];
|
||||
|
||||
var w = new C1(10, [undefined, undefined, undefined]);
|
||||
var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()];
|
||||
|
||||
@ -0,0 +1,63 @@
|
||||
//// [destructuringPropertyParameters3.ts]
|
||||
class C1<T, U, V> {
|
||||
constructor(private k: T, private [a, b, c]: [T,U,V]) {
|
||||
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
|
||||
this.a = a || k;
|
||||
}
|
||||
}
|
||||
|
||||
public getA() {
|
||||
return this.a
|
||||
}
|
||||
|
||||
public getB() {
|
||||
return this.b
|
||||
}
|
||||
|
||||
public getC() {
|
||||
return this.c;
|
||||
}
|
||||
}
|
||||
|
||||
var x = new C1(undefined, [0, true, ""]);
|
||||
var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()];
|
||||
|
||||
var y = new C1(10, [0, true, true]);
|
||||
var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()];
|
||||
|
||||
var z = new C1(10, [undefined, "", ""]);
|
||||
var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()];
|
||||
|
||||
var w = new C1(10, [undefined, undefined, undefined]);
|
||||
var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()];
|
||||
|
||||
|
||||
//// [destructuringPropertyParameters3.js]
|
||||
var C1 = (function () {
|
||||
function C1(k, _a) {
|
||||
var a = _a[0], b = _a[1], c = _a[2];
|
||||
this.k = k;
|
||||
this.[a, b, c] = [a, b, c];
|
||||
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
|
||||
this.a = a || k;
|
||||
}
|
||||
}
|
||||
C1.prototype.getA = function () {
|
||||
return this.a;
|
||||
};
|
||||
C1.prototype.getB = function () {
|
||||
return this.b;
|
||||
};
|
||||
C1.prototype.getC = function () {
|
||||
return this.c;
|
||||
};
|
||||
return C1;
|
||||
})();
|
||||
var x = new C1(undefined, [0, true, ""]);
|
||||
var _a = [x.getA(), x.getB(), x.getC()], x_a = _a[0], x_b = _a[1], x_c = _a[2];
|
||||
var y = new C1(10, [0, true, true]);
|
||||
var _b = [y.getA(), y.getB(), y.getC()], y_a = _b[0], y_b = _b[1], y_c = _b[2];
|
||||
var z = new C1(10, [undefined, "", ""]);
|
||||
var _c = [z.getA(), z.getB(), z.getC()], z_a = _c[0], z_b = _c[1], z_c = _c[2];
|
||||
var w = new C1(10, [undefined, undefined, undefined]);
|
||||
var _d = [z.getA(), z.getB(), z.getC()], z_a = _d[0], z_b = _d[1], z_c = _d[2];
|
||||
@ -0,0 +1,57 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(4,59): error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(4,83): error TS2339: Property 'c' does not exist on type 'C1<T, U, V>'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(5,18): error TS2339: Property 'a' does not exist on type 'C1<T, U, V>'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(10,21): error TS2339: Property 'a' does not exist on type 'C1<T, U, V>'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(14,21): error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(18,21): error TS2339: Property 'c' does not exist on type 'C1<T, U, V>'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(24,24): error TS2339: Property 'x' does not exist on type 'C2'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(24,34): error TS2339: Property 'y' does not exist on type 'C2'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts(24,44): error TS2339: Property 'z' does not exist on type 'C2'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters4.ts (9 errors) ====
|
||||
|
||||
class C1<T, U, V> {
|
||||
constructor(private k: T, protected [a, b, c]: [T,U,V]) {
|
||||
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
|
||||
~
|
||||
!!! error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
|
||||
~
|
||||
!!! error TS2339: Property 'c' does not exist on type 'C1<T, U, V>'.
|
||||
this.a = a || k;
|
||||
~
|
||||
!!! error TS2339: Property 'a' does not exist on type 'C1<T, U, V>'.
|
||||
}
|
||||
}
|
||||
|
||||
public getA() {
|
||||
return this.a
|
||||
~
|
||||
!!! error TS2339: Property 'a' does not exist on type 'C1<T, U, V>'.
|
||||
}
|
||||
|
||||
public getB() {
|
||||
return this.b
|
||||
~
|
||||
!!! error TS2339: Property 'b' does not exist on type 'C1<T, U, V>'.
|
||||
}
|
||||
|
||||
public getC() {
|
||||
return this.c;
|
||||
~
|
||||
!!! error TS2339: Property 'c' does not exist on type 'C1<T, U, V>'.
|
||||
}
|
||||
}
|
||||
|
||||
class C2 extends C1<number, string, boolean> {
|
||||
public doSomethingWithSuperProperties() {
|
||||
return `${this.x} ${this.y} ${this.z}`;
|
||||
~
|
||||
!!! error TS2339: Property 'x' does not exist on type 'C2'.
|
||||
~
|
||||
!!! error TS2339: Property 'y' does not exist on type 'C2'.
|
||||
~
|
||||
!!! error TS2339: Property 'z' does not exist on type 'C2'.
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
//// [destructuringPropertyParameters4.ts]
|
||||
|
||||
class C1<T, U, V> {
|
||||
constructor(private k: T, protected [a, b, c]: [T,U,V]) {
|
||||
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
|
||||
this.a = a || k;
|
||||
}
|
||||
}
|
||||
|
||||
public getA() {
|
||||
return this.a
|
||||
}
|
||||
|
||||
public getB() {
|
||||
return this.b
|
||||
}
|
||||
|
||||
public getC() {
|
||||
return this.c;
|
||||
}
|
||||
}
|
||||
|
||||
class C2 extends C1<number, string, boolean> {
|
||||
public doSomethingWithSuperProperties() {
|
||||
return `${this.x} ${this.y} ${this.z}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [destructuringPropertyParameters4.js]
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var C1 = (function () {
|
||||
function C1(k, [a, b, c]) {
|
||||
this.k = k;
|
||||
this.[a, b, c] = [a, b, c];
|
||||
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
|
||||
this.a = a || k;
|
||||
}
|
||||
}
|
||||
C1.prototype.getA = function () {
|
||||
return this.a;
|
||||
};
|
||||
C1.prototype.getB = function () {
|
||||
return this.b;
|
||||
};
|
||||
C1.prototype.getC = function () {
|
||||
return this.c;
|
||||
};
|
||||
return C1;
|
||||
})();
|
||||
var C2 = (function (_super) {
|
||||
__extends(C2, _super);
|
||||
function C2() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
C2.prototype.doSomethingWithSuperProperties = function () {
|
||||
return `${this.x} ${this.y} ${this.z}`;
|
||||
};
|
||||
return C2;
|
||||
})(C1);
|
||||
@ -0,0 +1,51 @@
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(5,27): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x1' and no string index signature.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(5,31): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x2' and no string index signature.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(5,35): error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x3' and no string index signature.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(7,29): error TS2339: Property 'x1' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(7,40): error TS2339: Property 'x2' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(7,51): error TS2339: Property 'x3' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(7,62): error TS2339: Property 'y' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(7,72): error TS2339: Property 'z' does not exist on type 'C1'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(11,16): error TS2345: Argument of type '[{ x1: number; x2: string; x3: boolean; }, string, boolean]' is not assignable to parameter of type '[{ x: number; y: string; z: boolean; }, number, string]'.
|
||||
Types of property '0' are incompatible.
|
||||
Type '{ x1: number; x2: string; x3: boolean; }' is not assignable to type '{ x: number; y: string; z: boolean; }'.
|
||||
Property 'x' is missing in type '{ x1: number; x2: string; x3: boolean; }'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts(11,56): error TS1005: ',' expected.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/destructuringPropertyParameters5.ts (10 errors) ====
|
||||
type ObjType1 = { x: number; y: string; z: boolean }
|
||||
type TupleType1 = [ObjType1, number, string]
|
||||
|
||||
class C1 {
|
||||
constructor(public [{ x1, x2, x3 }, y, z]: TupleType1) {
|
||||
~~
|
||||
!!! error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x1' and no string index signature.
|
||||
~~
|
||||
!!! error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x2' and no string index signature.
|
||||
~~
|
||||
!!! error TS2459: Type '{ x: number; y: string; z: boolean; }' has no property 'x3' and no string index signature.
|
||||
var foo: any = x1 || x2 || x3 || y || z;
|
||||
var bar: any = this.x1 || this.x2 || this.x3 || this.y || this.z;
|
||||
~~
|
||||
!!! error TS2339: Property 'x1' does not exist on type 'C1'.
|
||||
~~
|
||||
!!! error TS2339: Property 'x2' does not exist on type 'C1'.
|
||||
~~
|
||||
!!! error TS2339: Property 'x3' does not exist on type 'C1'.
|
||||
~
|
||||
!!! error TS2339: Property 'y' does not exist on type 'C1'.
|
||||
~
|
||||
!!! error TS2339: Property 'z' does not exist on type 'C1'.
|
||||
}
|
||||
}
|
||||
|
||||
var a = new C1([{ x1: 10, x2: "", x3: true }, "", false);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[{ x1: number; x2: string; x3: boolean; }, string, boolean]' is not assignable to parameter of type '[{ x: number; y: string; z: boolean; }, number, string]'.
|
||||
!!! error TS2345: Types of property '0' are incompatible.
|
||||
!!! error TS2345: Type '{ x1: number; x2: string; x3: boolean; }' is not assignable to type '{ x: number; y: string; z: boolean; }'.
|
||||
!!! error TS2345: Property 'x' is missing in type '{ x1: number; x2: string; x3: boolean; }'.
|
||||
~
|
||||
!!! error TS1005: ',' expected.
|
||||
var [a_x1, a_x2, a_x3, a_y, a_z] = [a.x1, a.x2, a.x3, a.y, a.z];
|
||||
@ -0,0 +1,29 @@
|
||||
class C1 {
|
||||
constructor(public [x, y, z]: string[]) {
|
||||
}
|
||||
}
|
||||
|
||||
type TupleType1 = [string, number, boolean];
|
||||
|
||||
class C2 {
|
||||
constructor(public [x, y, z]: TupleType1) {
|
||||
}
|
||||
}
|
||||
|
||||
type ObjType1 = { x: number; y: string; z: boolean }
|
||||
|
||||
class C3 {
|
||||
constructor(public { x, y, z }: ObjType1) {
|
||||
}
|
||||
}
|
||||
|
||||
var c1 = new C1([]);
|
||||
c1 = new C1(["larry", "{curly}", "moe"]);
|
||||
var useC1Properties = c1.x === c1.y && c1.y === c1.z;
|
||||
|
||||
var c2 = new C2(["10", 10, !!10]);
|
||||
var useC2Properties = c2.x === c2.y && c2.y === c2.z;
|
||||
|
||||
var c3 = new C3({x: 0, y: "", z: false});
|
||||
c3 = new C3({x: 0, "y", z: true});
|
||||
var useC3Properties = c3.x === c3.y && c3.y === c3.z;
|
||||
@ -0,0 +1,28 @@
|
||||
class C1 {
|
||||
constructor(private k: number, private [a, b, c]: [number, string, boolean]) {
|
||||
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
|
||||
this.a = a || k;
|
||||
}
|
||||
}
|
||||
|
||||
public getA() {
|
||||
return this.a
|
||||
}
|
||||
|
||||
public getB() {
|
||||
return this.b
|
||||
}
|
||||
|
||||
public getC() {
|
||||
return this.c;
|
||||
}
|
||||
}
|
||||
|
||||
var x = new C1(undefined, [0, undefined, ""]);
|
||||
var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()];
|
||||
|
||||
var y = new C1(10, [0, "", true]);
|
||||
var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()];
|
||||
|
||||
var z = new C1(10, [undefined, "", null]);
|
||||
var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()];
|
||||
@ -0,0 +1,31 @@
|
||||
class C1<T, U, V> {
|
||||
constructor(private k: T, private [a, b, c]: [T,U,V]) {
|
||||
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
|
||||
this.a = a || k;
|
||||
}
|
||||
}
|
||||
|
||||
public getA() {
|
||||
return this.a
|
||||
}
|
||||
|
||||
public getB() {
|
||||
return this.b
|
||||
}
|
||||
|
||||
public getC() {
|
||||
return this.c;
|
||||
}
|
||||
}
|
||||
|
||||
var x = new C1(undefined, [0, true, ""]);
|
||||
var [x_a, x_b, x_c] = [x.getA(), x.getB(), x.getC()];
|
||||
|
||||
var y = new C1(10, [0, true, true]);
|
||||
var [y_a, y_b, y_c] = [y.getA(), y.getB(), y.getC()];
|
||||
|
||||
var z = new C1(10, [undefined, "", ""]);
|
||||
var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()];
|
||||
|
||||
var w = new C1(10, [undefined, undefined, undefined]);
|
||||
var [z_a, z_b, z_c] = [z.getA(), z.getB(), z.getC()];
|
||||
@ -0,0 +1,27 @@
|
||||
// @target: es6
|
||||
|
||||
class C1<T, U, V> {
|
||||
constructor(private k: T, protected [a, b, c]: [T,U,V]) {
|
||||
if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) {
|
||||
this.a = a || k;
|
||||
}
|
||||
}
|
||||
|
||||
public getA() {
|
||||
return this.a
|
||||
}
|
||||
|
||||
public getB() {
|
||||
return this.b
|
||||
}
|
||||
|
||||
public getC() {
|
||||
return this.c;
|
||||
}
|
||||
}
|
||||
|
||||
class C2 extends C1<number, string, boolean> {
|
||||
public doSomethingWithSuperProperties() {
|
||||
return `${this.x} ${this.y} ${this.z}`;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
type ObjType1 = { x: number; y: string; z: boolean }
|
||||
type TupleType1 = [ObjType1, number, string]
|
||||
|
||||
class C1 {
|
||||
constructor(public [{ x1, x2, x3 }, y, z]: TupleType1) {
|
||||
var foo: any = x1 || x2 || x3 || y || z;
|
||||
var bar: any = this.x1 || this.x2 || this.x3 || this.y || this.z;
|
||||
}
|
||||
}
|
||||
|
||||
var a = new C1([{ x1: 10, x2: "", x3: true }, "", false);
|
||||
var [a_x1, a_x2, a_x3, a_y, a_z] = [a.x1, a.x2, a.x3, a.y, a.z];
|
||||
Loading…
x
Reference in New Issue
Block a user