Skip to content

Commit

Permalink
Test a setter
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Dec 9, 2021
1 parent 5eb70f8 commit d45768e
Show file tree
Hide file tree
Showing 5 changed files with 446 additions and 298 deletions.
185 changes: 112 additions & 73 deletions tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt
Original file line number Diff line number Diff line change
@@ -1,96 +1,135 @@
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(4,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(14,15): error TS2339: Property 'bar' does not exist on type 'Omit<this, "bar" | "func">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(15,15): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(16,15): error TS2339: Property 'bar' does not exist on type 'Omit<this, "foo" | "bar" | "func">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(17,15): error TS2339: Property 'bar' does not exist on type '{}'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(19,15): error TS2339: Property 'func' does not exist on type 'Omit<this, "bar" | "func">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(20,15): error TS2339: Property 'func' does not exist on type '{ foo: string; }'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(21,15): error TS2339: Property 'func' does not exist on type 'Omit<this, "foo" | "bar" | "func">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(22,15): error TS2339: Property 'func' does not exist on type '{}'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(32,11): error TS2339: Property 'bar' does not exist on type 'Omit<T, "bar" | "func">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(33,11): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(34,11): error TS2339: Property 'bar' does not exist on type 'Omit<T, "foo" | "bar" | "func">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(35,11): error TS2339: Property 'bar' does not exist on type '{}'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(37,11): error TS2339: Property 'func' does not exist on type 'Omit<T, "bar" | "func">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(38,11): error TS2339: Property 'func' does not exist on type '{ foo: string; }'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(39,11): error TS2339: Property 'func' does not exist on type 'Omit<T, "foo" | "bar" | "func">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(40,11): error TS2339: Property 'func' does not exist on type '{}'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(16,15): error TS2339: Property 'getter' does not exist on type 'Omit<this, "getter" | "setter" | "method">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(17,15): error TS2339: Property 'getter' does not exist on type '{ normal: string; }'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(18,15): error TS2339: Property 'getter' does not exist on type 'Omit<this, "normal" | "getter" | "setter" | "method">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(19,15): error TS2339: Property 'getter' does not exist on type '{}'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(21,15): error TS2339: Property 'setter' does not exist on type 'Omit<this, "getter" | "setter" | "method">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(22,15): error TS2339: Property 'setter' does not exist on type '{ normal: string; }'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(23,15): error TS2339: Property 'setter' does not exist on type 'Omit<this, "normal" | "getter" | "setter" | "method">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(24,15): error TS2339: Property 'setter' does not exist on type '{}'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(26,15): error TS2339: Property 'method' does not exist on type 'Omit<this, "getter" | "setter" | "method">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(27,15): error TS2339: Property 'method' does not exist on type '{ normal: string; }'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(28,15): error TS2339: Property 'method' does not exist on type 'Omit<this, "normal" | "getter" | "setter" | "method">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(29,15): error TS2339: Property 'method' does not exist on type '{}'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(39,11): error TS2339: Property 'getter' does not exist on type 'Omit<T, "getter" | "setter" | "method">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(40,11): error TS2339: Property 'getter' does not exist on type '{ normal: string; }'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(41,11): error TS2339: Property 'getter' does not exist on type 'Omit<T, "normal" | "getter" | "setter" | "method">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(42,11): error TS2339: Property 'getter' does not exist on type '{}'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(44,11): error TS2339: Property 'setter' does not exist on type 'Omit<T, "getter" | "setter" | "method">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(45,11): error TS2339: Property 'setter' does not exist on type '{ normal: string; }'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(46,11): error TS2339: Property 'setter' does not exist on type 'Omit<T, "normal" | "getter" | "setter" | "method">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(47,11): error TS2339: Property 'setter' does not exist on type '{}'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(49,11): error TS2339: Property 'method' does not exist on type 'Omit<T, "getter" | "setter" | "method">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(50,11): error TS2339: Property 'method' does not exist on type '{ normal: string; }'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(51,11): error TS2339: Property 'method' does not exist on type 'Omit<T, "normal" | "getter" | "setter" | "method">'.
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(52,11): error TS2339: Property 'method' does not exist on type '{}'.


==== tests/cases/compiler/destructuringUnspreadableIntoRest.ts (17 errors) ====
==== tests/cases/compiler/destructuringUnspreadableIntoRest.ts (26 errors) ====
class A {
constructor(public foo: string) {}
constructor(public normal: string) {}

get bar(): number {
~~~
get getter(): number {
~~~~~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
return 1;
}

func() {
set setter(_v: number) {}
~~~~~~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.

method() {
const { ...rest1 } = this;
const { ...rest2 } = this as A;
const { foo: _f1, ...rest3 } = this;
const { foo: _f2, ...rest4 } = this as A;
const { normal: _1, ...rest3 } = this;
const { normal: _2, ...rest4 } = this as A;

rest1.bar;
~~~
!!! error TS2339: Property 'bar' does not exist on type 'Omit<this, "bar" | "func">'.
rest2.bar;
~~~
!!! error TS2339: Property 'bar' does not exist on type '{ foo: string; }'.
rest3.bar;
~~~
!!! error TS2339: Property 'bar' does not exist on type 'Omit<this, "foo" | "bar" | "func">'.
rest4.bar;
~~~
!!! error TS2339: Property 'bar' does not exist on type '{}'.
rest1.getter;
~~~~~~
!!! error TS2339: Property 'getter' does not exist on type 'Omit<this, "getter" | "setter" | "method">'.
rest2.getter;
~~~~~~
!!! error TS2339: Property 'getter' does not exist on type '{ normal: string; }'.
rest3.getter;
~~~~~~
!!! error TS2339: Property 'getter' does not exist on type 'Omit<this, "normal" | "getter" | "setter" | "method">'.
rest4.getter;
~~~~~~
!!! error TS2339: Property 'getter' does not exist on type '{}'.

rest1.func;
~~~~
!!! error TS2339: Property 'func' does not exist on type 'Omit<this, "bar" | "func">'.
rest2.func;
~~~~
!!! error TS2339: Property 'func' does not exist on type '{ foo: string; }'.
rest3.func;
~~~~
!!! error TS2339: Property 'func' does not exist on type 'Omit<this, "foo" | "bar" | "func">'.
rest4.func;
~~~~
!!! error TS2339: Property 'func' does not exist on type '{}'.
rest1.setter;
~~~~~~
!!! error TS2339: Property 'setter' does not exist on type 'Omit<this, "getter" | "setter" | "method">'.
rest2.setter;
~~~~~~
!!! error TS2339: Property 'setter' does not exist on type '{ normal: string; }'.
rest3.setter;
~~~~~~
!!! error TS2339: Property 'setter' does not exist on type 'Omit<this, "normal" | "getter" | "setter" | "method">'.
rest4.setter;
~~~~~~
!!! error TS2339: Property 'setter' does not exist on type '{}'.

rest1.method;
~~~~~~
!!! error TS2339: Property 'method' does not exist on type 'Omit<this, "getter" | "setter" | "method">'.
rest2.method;
~~~~~~
!!! error TS2339: Property 'method' does not exist on type '{ normal: string; }'.
rest3.method;
~~~~~~
!!! error TS2339: Property 'method' does not exist on type 'Omit<this, "normal" | "getter" | "setter" | "method">'.
rest4.method;
~~~~~~
!!! error TS2339: Property 'method' does not exist on type '{}'.
}
}

function destructure<T extends A>(x: T) {
const { ...rest1 } = x;
const { ...rest2 } = x as A;
const { foo: _f1, ...rest3 } = x;
const { foo: _f2, ...rest4 } = x as A;
const { normal: _1, ...rest3 } = x;
const { normal: _2, ...rest4 } = x as A;

rest1.getter;
~~~~~~
!!! error TS2339: Property 'getter' does not exist on type 'Omit<T, "getter" | "setter" | "method">'.
rest2.getter;
~~~~~~
!!! error TS2339: Property 'getter' does not exist on type '{ normal: string; }'.
rest3.getter;
~~~~~~
!!! error TS2339: Property 'getter' does not exist on type 'Omit<T, "normal" | "getter" | "setter" | "method">'.
rest4.getter;
~~~~~~
!!! error TS2339: Property 'getter' does not exist on type '{}'.

rest1.bar;
~~~
!!! error TS2339: Property 'bar' does not exist on type 'Omit<T, "bar" | "func">'.
rest2.bar;
~~~
!!! error TS2339: Property 'bar' does not exist on type '{ foo: string; }'.
rest3.bar;
~~~
!!! error TS2339: Property 'bar' does not exist on type 'Omit<T, "foo" | "bar" | "func">'.
rest4.bar;
~~~
!!! error TS2339: Property 'bar' does not exist on type '{}'.
rest1.setter;
~~~~~~
!!! error TS2339: Property 'setter' does not exist on type 'Omit<T, "getter" | "setter" | "method">'.
rest2.setter;
~~~~~~
!!! error TS2339: Property 'setter' does not exist on type '{ normal: string; }'.
rest3.setter;
~~~~~~
!!! error TS2339: Property 'setter' does not exist on type 'Omit<T, "normal" | "getter" | "setter" | "method">'.
rest4.setter;
~~~~~~
!!! error TS2339: Property 'setter' does not exist on type '{}'.

rest1.func;
~~~~
!!! error TS2339: Property 'func' does not exist on type 'Omit<T, "bar" | "func">'.
rest2.func;
~~~~
!!! error TS2339: Property 'func' does not exist on type '{ foo: string; }'.
rest3.func;
~~~~
!!! error TS2339: Property 'func' does not exist on type 'Omit<T, "foo" | "bar" | "func">'.
rest4.func;
~~~~
!!! error TS2339: Property 'func' does not exist on type '{}'.
rest1.method;
~~~~~~
!!! error TS2339: Property 'method' does not exist on type 'Omit<T, "getter" | "setter" | "method">'.
rest2.method;
~~~~~~
!!! error TS2339: Property 'method' does not exist on type '{ normal: string; }'.
rest3.method;
~~~~~~
!!! error TS2339: Property 'method' does not exist on type 'Omit<T, "normal" | "getter" | "setter" | "method">'.
rest4.method;
~~~~~~
!!! error TS2339: Property 'method' does not exist on type '{}'.
}

119 changes: 72 additions & 47 deletions tests/baselines/reference/destructuringUnspreadableIntoRest.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
//// [destructuringUnspreadableIntoRest.ts]
class A {
constructor(public foo: string) {}
constructor(public normal: string) {}

get bar(): number {
get getter(): number {
return 1;
}

func() {
set setter(_v: number) {}

method() {
const { ...rest1 } = this;
const { ...rest2 } = this as A;
const { foo: _f1, ...rest3 } = this;
const { foo: _f2, ...rest4 } = this as A;
const { normal: _1, ...rest3 } = this;
const { normal: _2, ...rest4 } = this as A;

rest1.getter;
rest2.getter;
rest3.getter;
rest4.getter;

rest1.bar;
rest2.bar;
rest3.bar;
rest4.bar;
rest1.setter;
rest2.setter;
rest3.setter;
rest4.setter;

rest1.func;
rest2.func;
rest3.func;
rest4.func;
rest1.method;
rest2.method;
rest3.method;
rest4.method;
}
}

function destructure<T extends A>(x: T) {
const { ...rest1 } = x;
const { ...rest2 } = x as A;
const { foo: _f1, ...rest3 } = x;
const { foo: _f2, ...rest4 } = x as A;
const { normal: _1, ...rest3 } = x;
const { normal: _2, ...rest4 } = x as A;

rest1.getter;
rest2.getter;
rest3.getter;
rest4.getter;

rest1.bar;
rest2.bar;
rest3.bar;
rest4.bar;
rest1.setter;
rest2.setter;
rest3.setter;
rest4.setter;

rest1.func;
rest2.func;
rest3.func;
rest4.func;
rest1.method;
rest2.method;
rest3.method;
rest4.method;
}


Expand All @@ -55,43 +67,56 @@ var __rest = (this && this.__rest) || function (s, e) {
return t;
};
var A = /** @class */ (function () {
function A(foo) {
this.foo = foo;
function A(normal) {
this.normal = normal;
}
Object.defineProperty(A.prototype, "bar", {
Object.defineProperty(A.prototype, "getter", {
get: function () {
return 1;
},
enumerable: false,
configurable: true
});
A.prototype.func = function () {
Object.defineProperty(A.prototype, "setter", {
set: function (_v) { },
enumerable: false,
configurable: true
});
A.prototype.method = function () {
var rest1 = __rest(this, []);
var rest2 = __rest(this, []);
var _a = this, _f1 = _a.foo, rest3 = __rest(_a, ["foo"]);
var _b = this, _f2 = _b.foo, rest4 = __rest(_b, ["foo"]);
rest1.bar;
rest2.bar;
rest3.bar;
rest4.bar;
rest1.func;
rest2.func;
rest3.func;
rest4.func;
var _a = this, _1 = _a.normal, rest3 = __rest(_a, ["normal"]);
var _b = this, _2 = _b.normal, rest4 = __rest(_b, ["normal"]);
rest1.getter;
rest2.getter;
rest3.getter;
rest4.getter;
rest1.setter;
rest2.setter;
rest3.setter;
rest4.setter;
rest1.method;
rest2.method;
rest3.method;
rest4.method;
};
return A;
}());
function destructure(x) {
var rest1 = __rest(x, []);
var rest2 = __rest(x, []);
var _f1 = x.foo, rest3 = __rest(x, ["foo"]);
var _a = x, _f2 = _a.foo, rest4 = __rest(_a, ["foo"]);
rest1.bar;
rest2.bar;
rest3.bar;
rest4.bar;
rest1.func;
rest2.func;
rest3.func;
rest4.func;
var _1 = x.normal, rest3 = __rest(x, ["normal"]);
var _a = x, _2 = _a.normal, rest4 = __rest(_a, ["normal"]);
rest1.getter;
rest2.getter;
rest3.getter;
rest4.getter;
rest1.setter;
rest2.setter;
rest3.setter;
rest4.setter;
rest1.method;
rest2.method;
rest3.method;
rest4.method;
}
Loading

0 comments on commit d45768e

Please sign in to comment.