From f532408291d52d11139a7a7ded2a3cf57cf31810 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 7 Dec 2021 15:24:22 -0800 Subject: [PATCH 1/9] Add test case --- .../destructuringThisWithProperty.errors.txt | 34 ++++++++++ .../destructuringThisWithProperty.js | 61 ++++++++++++++++++ .../destructuringThisWithProperty.symbols | 58 +++++++++++++++++ .../destructuringThisWithProperty.types | 63 +++++++++++++++++++ .../compiler/destructuringThisWithProperty.ts | 21 +++++++ 5 files changed, 237 insertions(+) create mode 100644 tests/baselines/reference/destructuringThisWithProperty.errors.txt create mode 100644 tests/baselines/reference/destructuringThisWithProperty.js create mode 100644 tests/baselines/reference/destructuringThisWithProperty.symbols create mode 100644 tests/baselines/reference/destructuringThisWithProperty.types create mode 100644 tests/cases/compiler/destructuringThisWithProperty.ts diff --git a/tests/baselines/reference/destructuringThisWithProperty.errors.txt b/tests/baselines/reference/destructuringThisWithProperty.errors.txt new file mode 100644 index 0000000000000..8e4b0d915c6eb --- /dev/null +++ b/tests/baselines/reference/destructuringThisWithProperty.errors.txt @@ -0,0 +1,34 @@ +tests/cases/compiler/destructuringThisWithProperty.ts(4,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/destructuringThisWithProperty.ts(17,15): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. +tests/cases/compiler/destructuringThisWithProperty.ts(19,15): error TS2339: Property 'bar' does not exist on type '{}'. + + +==== tests/cases/compiler/destructuringThisWithProperty.ts (3 errors) ==== + class A { + constructor(public foo: string) {} + + get bar(): number { + ~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + return 1; + } + + func() { + const { ...rest1 } = this; + const { ...rest2 } = this as A; + const { foo: _f1, ...rest3 } = this; + const { foo: _f2, ...rest4 } = this as A; + + // Rest destructuring drops properties provided by getters. + // "bar" should not be present in any of these. + rest1.bar; + rest2.bar; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. + rest3.bar; + rest4.bar; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type '{}'. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringThisWithProperty.js b/tests/baselines/reference/destructuringThisWithProperty.js new file mode 100644 index 0000000000000..e0f0e6b2a2ef1 --- /dev/null +++ b/tests/baselines/reference/destructuringThisWithProperty.js @@ -0,0 +1,61 @@ +//// [destructuringThisWithProperty.ts] +class A { + constructor(public foo: string) {} + + get bar(): number { + return 1; + } + + func() { + const { ...rest1 } = this; + const { ...rest2 } = this as A; + const { foo: _f1, ...rest3 } = this; + const { foo: _f2, ...rest4 } = this as A; + + // Rest destructuring drops properties provided by getters. + // "bar" should not be present in any of these. + rest1.bar; + rest2.bar; + rest3.bar; + rest4.bar; + } +} + + +//// [destructuringThisWithProperty.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var A = /** @class */ (function () { + function A(foo) { + this.foo = foo; + } + Object.defineProperty(A.prototype, "bar", { + get: function () { + return 1; + }, + enumerable: false, + configurable: true + }); + A.prototype.func = 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"]); + // Rest destructuring drops properties provided by getters. + // "bar" should not be present in any of these. + rest1.bar; + rest2.bar; + rest3.bar; + rest4.bar; + }; + return A; +}()); diff --git a/tests/baselines/reference/destructuringThisWithProperty.symbols b/tests/baselines/reference/destructuringThisWithProperty.symbols new file mode 100644 index 0000000000000..f6742c8d667e5 --- /dev/null +++ b/tests/baselines/reference/destructuringThisWithProperty.symbols @@ -0,0 +1,58 @@ +=== tests/cases/compiler/destructuringThisWithProperty.ts === +class A { +>A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) + + constructor(public foo: string) {} +>foo : Symbol(A.foo, Decl(destructuringThisWithProperty.ts, 1, 16)) + + get bar(): number { +>bar : Symbol(A.bar, Decl(destructuringThisWithProperty.ts, 1, 38)) + + return 1; + } + + func() { +>func : Symbol(A.func, Decl(destructuringThisWithProperty.ts, 5, 5)) + + const { ...rest1 } = this; +>rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 8, 15)) +>this : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) + + const { ...rest2 } = this as A; +>rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 9, 15)) +>this : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) +>A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) + + const { foo: _f1, ...rest3 } = this; +>foo : Symbol(A.foo, Decl(destructuringThisWithProperty.ts, 1, 16)) +>_f1 : Symbol(_f1, Decl(destructuringThisWithProperty.ts, 10, 15)) +>rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 10, 25)) +>this : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) + + const { foo: _f2, ...rest4 } = this as A; +>foo : Symbol(A.foo, Decl(destructuringThisWithProperty.ts, 1, 16)) +>_f2 : Symbol(_f2, Decl(destructuringThisWithProperty.ts, 11, 15)) +>rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 11, 25)) +>this : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) +>A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) + + // Rest destructuring drops properties provided by getters. + // "bar" should not be present in any of these. + rest1.bar; +>rest1.bar : Symbol(A.bar, Decl(destructuringThisWithProperty.ts, 1, 38)) +>rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 8, 15)) +>bar : Symbol(A.bar, Decl(destructuringThisWithProperty.ts, 1, 38)) + + rest2.bar; +>rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 9, 15)) + + rest3.bar; +>rest3.bar : Symbol(bar, Decl(destructuringThisWithProperty.ts, 1, 38)) +>rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 10, 25)) +>bar : Symbol(bar, Decl(destructuringThisWithProperty.ts, 1, 38)) + + rest4.bar; +>rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 11, 25)) + } +} + diff --git a/tests/baselines/reference/destructuringThisWithProperty.types b/tests/baselines/reference/destructuringThisWithProperty.types new file mode 100644 index 0000000000000..17da44249f275 --- /dev/null +++ b/tests/baselines/reference/destructuringThisWithProperty.types @@ -0,0 +1,63 @@ +=== tests/cases/compiler/destructuringThisWithProperty.ts === +class A { +>A : A + + constructor(public foo: string) {} +>foo : string + + get bar(): number { +>bar : number + + return 1; +>1 : 1 + } + + func() { +>func : () => void + + const { ...rest1 } = this; +>rest1 : this +>this : this + + const { ...rest2 } = this as A; +>rest2 : { foo: string; } +>this as A : A +>this : this + + const { foo: _f1, ...rest3 } = this; +>foo : any +>_f1 : string +>rest3 : Omit +>this : this + + const { foo: _f2, ...rest4 } = this as A; +>foo : any +>_f2 : string +>rest4 : {} +>this as A : A +>this : this + + // Rest destructuring drops properties provided by getters. + // "bar" should not be present in any of these. + rest1.bar; +>rest1.bar : number +>rest1 : this +>bar : number + + rest2.bar; +>rest2.bar : any +>rest2 : { foo: string; } +>bar : any + + rest3.bar; +>rest3.bar : this["bar"] +>rest3 : Omit +>bar : this["bar"] + + rest4.bar; +>rest4.bar : any +>rest4 : {} +>bar : any + } +} + diff --git a/tests/cases/compiler/destructuringThisWithProperty.ts b/tests/cases/compiler/destructuringThisWithProperty.ts new file mode 100644 index 0000000000000..2c9ae737fd2a1 --- /dev/null +++ b/tests/cases/compiler/destructuringThisWithProperty.ts @@ -0,0 +1,21 @@ +class A { + constructor(public foo: string) {} + + get bar(): number { + return 1; + } + + func() { + const { ...rest1 } = this; + const { ...rest2 } = this as A; + const { foo: _f1, ...rest3 } = this; + const { foo: _f2, ...rest4 } = this as A; + + // Rest destructuring drops properties provided by getters. + // "bar" should not be present in any of these. + rest1.bar; + rest2.bar; + rest3.bar; + rest4.bar; + } +} From d213a4d6556530ea2f8a58725ea127b8633e7285 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 8 Dec 2021 17:03:50 -0800 Subject: [PATCH 2/9] Do not use Omit on this when getting rest type --- src/compiler/checker.ts | 2 +- .../destructuringThisWithProperty.errors.txt | 8 +++++++- .../destructuringThisWithProperty.symbols | 4 ---- .../destructuringThisWithProperty.types | 16 ++++++++-------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 56a36f658d719..836e97433a780 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8465,7 +8465,7 @@ namespace ts { return mapType(source, t => getRestType(t, properties, symbol)); } const omitKeyType = getUnionType(map(properties, getLiteralTypeFromPropertyName)); - if (isGenericObjectType(source) || isGenericIndexType(omitKeyType)) { + if (!isThisTypeParameter(source) && (isGenericObjectType(source) || isGenericIndexType(omitKeyType))) { if (omitKeyType.flags & TypeFlags.Never) { return source; } diff --git a/tests/baselines/reference/destructuringThisWithProperty.errors.txt b/tests/baselines/reference/destructuringThisWithProperty.errors.txt index 8e4b0d915c6eb..7da6a03c55147 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.errors.txt +++ b/tests/baselines/reference/destructuringThisWithProperty.errors.txt @@ -1,9 +1,11 @@ tests/cases/compiler/destructuringThisWithProperty.ts(4,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/compiler/destructuringThisWithProperty.ts(16,15): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. tests/cases/compiler/destructuringThisWithProperty.ts(17,15): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. +tests/cases/compiler/destructuringThisWithProperty.ts(18,15): error TS2339: Property 'bar' does not exist on type '{}'. tests/cases/compiler/destructuringThisWithProperty.ts(19,15): error TS2339: Property 'bar' does not exist on type '{}'. -==== tests/cases/compiler/destructuringThisWithProperty.ts (3 errors) ==== +==== tests/cases/compiler/destructuringThisWithProperty.ts (5 errors) ==== class A { constructor(public foo: string) {} @@ -22,10 +24,14 @@ tests/cases/compiler/destructuringThisWithProperty.ts(19,15): error TS2339: Prop // Rest destructuring drops properties provided by getters. // "bar" should not be present in any of these. rest1.bar; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. rest2.bar; ~~~ !!! error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. rest3.bar; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type '{}'. rest4.bar; ~~~ !!! error TS2339: Property 'bar' does not exist on type '{}'. diff --git a/tests/baselines/reference/destructuringThisWithProperty.symbols b/tests/baselines/reference/destructuringThisWithProperty.symbols index f6742c8d667e5..497ad38cf640c 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.symbols +++ b/tests/baselines/reference/destructuringThisWithProperty.symbols @@ -39,17 +39,13 @@ class A { // Rest destructuring drops properties provided by getters. // "bar" should not be present in any of these. rest1.bar; ->rest1.bar : Symbol(A.bar, Decl(destructuringThisWithProperty.ts, 1, 38)) >rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 8, 15)) ->bar : Symbol(A.bar, Decl(destructuringThisWithProperty.ts, 1, 38)) rest2.bar; >rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 9, 15)) rest3.bar; ->rest3.bar : Symbol(bar, Decl(destructuringThisWithProperty.ts, 1, 38)) >rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 10, 25)) ->bar : Symbol(bar, Decl(destructuringThisWithProperty.ts, 1, 38)) rest4.bar; >rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 11, 25)) diff --git a/tests/baselines/reference/destructuringThisWithProperty.types b/tests/baselines/reference/destructuringThisWithProperty.types index 17da44249f275..0defe17198d4d 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.types +++ b/tests/baselines/reference/destructuringThisWithProperty.types @@ -16,7 +16,7 @@ class A { >func : () => void const { ...rest1 } = this; ->rest1 : this +>rest1 : { foo: string; } >this : this const { ...rest2 } = this as A; @@ -27,7 +27,7 @@ class A { const { foo: _f1, ...rest3 } = this; >foo : any >_f1 : string ->rest3 : Omit +>rest3 : {} >this : this const { foo: _f2, ...rest4 } = this as A; @@ -40,9 +40,9 @@ class A { // Rest destructuring drops properties provided by getters. // "bar" should not be present in any of these. rest1.bar; ->rest1.bar : number ->rest1 : this ->bar : number +>rest1.bar : any +>rest1 : { foo: string; } +>bar : any rest2.bar; >rest2.bar : any @@ -50,9 +50,9 @@ class A { >bar : any rest3.bar; ->rest3.bar : this["bar"] ->rest3 : Omit ->bar : this["bar"] +>rest3.bar : any +>rest3 : {} +>bar : any rest4.bar; >rest4.bar : any From 57a6ef7b54198b73bfaa0249f91b15610bb01fba Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 8 Dec 2021 17:15:37 -0800 Subject: [PATCH 3/9] Add failing test case for regular type param --- .../destructuringThisWithProperty.errors.txt | 22 ++++++++- .../destructuringThisWithProperty.js | 26 ++++++++++ .../destructuringThisWithProperty.symbols | 48 ++++++++++++++++++ .../destructuringThisWithProperty.types | 49 +++++++++++++++++++ .../compiler/destructuringThisWithProperty.ts | 14 ++++++ 5 files changed, 158 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/destructuringThisWithProperty.errors.txt b/tests/baselines/reference/destructuringThisWithProperty.errors.txt index 7da6a03c55147..4e5186a3e3614 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.errors.txt +++ b/tests/baselines/reference/destructuringThisWithProperty.errors.txt @@ -3,9 +3,11 @@ tests/cases/compiler/destructuringThisWithProperty.ts(16,15): error TS2339: Prop tests/cases/compiler/destructuringThisWithProperty.ts(17,15): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. tests/cases/compiler/destructuringThisWithProperty.ts(18,15): error TS2339: Property 'bar' does not exist on type '{}'. tests/cases/compiler/destructuringThisWithProperty.ts(19,15): error TS2339: Property 'bar' does not exist on type '{}'. +tests/cases/compiler/destructuringThisWithProperty.ts(32,11): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. +tests/cases/compiler/destructuringThisWithProperty.ts(34,11): error TS2339: Property 'bar' does not exist on type '{}'. -==== tests/cases/compiler/destructuringThisWithProperty.ts (5 errors) ==== +==== tests/cases/compiler/destructuringThisWithProperty.ts (7 errors) ==== class A { constructor(public foo: string) {} @@ -37,4 +39,22 @@ tests/cases/compiler/destructuringThisWithProperty.ts(19,15): error TS2339: Prop !!! error TS2339: Property 'bar' does not exist on type '{}'. } } + + function destructure(x: T) { + const { ...rest1 } = x; + const { ...rest2 } = x as A; + const { foo: _f1, ...rest3 } = x; + const { foo: _f2, ...rest4 } = x as A; + + // Rest destructuring drops properties provided by getters. + // "bar" should not be present in any of these. + rest1.bar; + rest2.bar; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. + rest3.bar; + rest4.bar; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type '{}'. + } \ No newline at end of file diff --git a/tests/baselines/reference/destructuringThisWithProperty.js b/tests/baselines/reference/destructuringThisWithProperty.js index e0f0e6b2a2ef1..e8d141b29f80d 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.js +++ b/tests/baselines/reference/destructuringThisWithProperty.js @@ -20,6 +20,20 @@ class A { rest4.bar; } } + +function destructure(x: T) { + const { ...rest1 } = x; + const { ...rest2 } = x as A; + const { foo: _f1, ...rest3 } = x; + const { foo: _f2, ...rest4 } = x as A; + + // Rest destructuring drops properties provided by getters. + // "bar" should not be present in any of these. + rest1.bar; + rest2.bar; + rest3.bar; + rest4.bar; +} //// [destructuringThisWithProperty.js] @@ -59,3 +73,15 @@ var A = /** @class */ (function () { }; 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"]); + // Rest destructuring drops properties provided by getters. + // "bar" should not be present in any of these. + rest1.bar; + rest2.bar; + rest3.bar; + rest4.bar; +} diff --git a/tests/baselines/reference/destructuringThisWithProperty.symbols b/tests/baselines/reference/destructuringThisWithProperty.symbols index 497ad38cf640c..d11afef6d3845 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.symbols +++ b/tests/baselines/reference/destructuringThisWithProperty.symbols @@ -52,3 +52,51 @@ class A { } } +function destructure(x: T) { +>destructure : Symbol(destructure, Decl(destructuringThisWithProperty.ts, 20, 1)) +>T : Symbol(T, Decl(destructuringThisWithProperty.ts, 22, 21)) +>A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) +>x : Symbol(x, Decl(destructuringThisWithProperty.ts, 22, 34)) +>T : Symbol(T, Decl(destructuringThisWithProperty.ts, 22, 21)) + + const { ...rest1 } = x; +>rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 23, 11)) +>x : Symbol(x, Decl(destructuringThisWithProperty.ts, 22, 34)) + + const { ...rest2 } = x as A; +>rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 24, 11)) +>x : Symbol(x, Decl(destructuringThisWithProperty.ts, 22, 34)) +>A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) + + const { foo: _f1, ...rest3 } = x; +>foo : Symbol(A.foo, Decl(destructuringThisWithProperty.ts, 1, 16)) +>_f1 : Symbol(_f1, Decl(destructuringThisWithProperty.ts, 25, 11)) +>rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 25, 21)) +>x : Symbol(x, Decl(destructuringThisWithProperty.ts, 22, 34)) + + const { foo: _f2, ...rest4 } = x as A; +>foo : Symbol(A.foo, Decl(destructuringThisWithProperty.ts, 1, 16)) +>_f2 : Symbol(_f2, Decl(destructuringThisWithProperty.ts, 26, 11)) +>rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 26, 21)) +>x : Symbol(x, Decl(destructuringThisWithProperty.ts, 22, 34)) +>A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) + + // Rest destructuring drops properties provided by getters. + // "bar" should not be present in any of these. + rest1.bar; +>rest1.bar : Symbol(A.bar, Decl(destructuringThisWithProperty.ts, 1, 38)) +>rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 23, 11)) +>bar : Symbol(A.bar, Decl(destructuringThisWithProperty.ts, 1, 38)) + + rest2.bar; +>rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 24, 11)) + + rest3.bar; +>rest3.bar : Symbol(bar, Decl(destructuringThisWithProperty.ts, 1, 38)) +>rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 25, 21)) +>bar : Symbol(bar, Decl(destructuringThisWithProperty.ts, 1, 38)) + + rest4.bar; +>rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 26, 21)) +} + diff --git a/tests/baselines/reference/destructuringThisWithProperty.types b/tests/baselines/reference/destructuringThisWithProperty.types index 0defe17198d4d..50a50f3c9f2e8 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.types +++ b/tests/baselines/reference/destructuringThisWithProperty.types @@ -61,3 +61,52 @@ class A { } } +function destructure(x: T) { +>destructure : (x: T) => void +>x : T + + const { ...rest1 } = x; +>rest1 : T +>x : T + + const { ...rest2 } = x as A; +>rest2 : { foo: string; } +>x as A : A +>x : T + + const { foo: _f1, ...rest3 } = x; +>foo : any +>_f1 : string +>rest3 : Omit +>x : T + + const { foo: _f2, ...rest4 } = x as A; +>foo : any +>_f2 : string +>rest4 : {} +>x as A : A +>x : T + + // Rest destructuring drops properties provided by getters. + // "bar" should not be present in any of these. + rest1.bar; +>rest1.bar : number +>rest1 : T +>bar : number + + rest2.bar; +>rest2.bar : any +>rest2 : { foo: string; } +>bar : any + + rest3.bar; +>rest3.bar : T["bar"] +>rest3 : Omit +>bar : T["bar"] + + rest4.bar; +>rest4.bar : any +>rest4 : {} +>bar : any +} + diff --git a/tests/cases/compiler/destructuringThisWithProperty.ts b/tests/cases/compiler/destructuringThisWithProperty.ts index 2c9ae737fd2a1..be33a519bd052 100644 --- a/tests/cases/compiler/destructuringThisWithProperty.ts +++ b/tests/cases/compiler/destructuringThisWithProperty.ts @@ -19,3 +19,17 @@ class A { rest4.bar; } } + +function destructure(x: T) { + const { ...rest1 } = x; + const { ...rest2 } = x as A; + const { foo: _f1, ...rest3 } = x; + const { foo: _f2, ...rest4 } = x as A; + + // Rest destructuring drops properties provided by getters. + // "bar" should not be present in any of these. + rest1.bar; + rest2.bar; + rest3.bar; + rest4.bar; +} From db5e9fafb638f2ae2af796eb065d74e397da90da Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 8 Dec 2021 19:26:33 -0800 Subject: [PATCH 4/9] Explicitly omit keys unspreadable in rest --- src/compiler/checker.ts | 36 ++++++++++++++----- .../destructuringThisWithProperty.errors.txt | 16 ++++++--- .../destructuringThisWithProperty.symbols | 4 --- .../destructuringThisWithProperty.types | 24 ++++++------- 4 files changed, 51 insertions(+), 29 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 836e97433a780..da42eefed3d6d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8464,8 +8464,32 @@ namespace ts { if (source.flags & TypeFlags.Union) { return mapType(source, t => getRestType(t, properties, symbol)); } - const omitKeyType = getUnionType(map(properties, getLiteralTypeFromPropertyName)); - if (!isThisTypeParameter(source) && (isGenericObjectType(source) || isGenericIndexType(omitKeyType))) { + + let omitKeyType = getUnionType(map(properties, getLiteralTypeFromPropertyName)); + + const spreadableProperties: Symbol[] = []; + const unspreadableToRestKeys: Type[] = []; + + for (const prop of getPropertiesOfType(source)) { + const literalTypeFromProperty = getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique); + if (!isTypeAssignableTo(literalTypeFromProperty, omitKeyType) + && !(getDeclarationModifierFlagsFromSymbol(prop) & (ModifierFlags.Private | ModifierFlags.Protected)) + && isSpreadableProperty(prop)) { + spreadableProperties.push(prop); + } + else { + unspreadableToRestKeys.push(literalTypeFromProperty); + } + } + + if (isGenericObjectType(source) || isGenericIndexType(omitKeyType)) { + if (unspreadableToRestKeys.length) { + // If the type we're spreading from has properties that cannot + // be spread into the rest type (e.g. getters, methods), ensure + // they are explicitly omitted, as they would in the non-generic case. + omitKeyType = getUnionType([omitKeyType, ...unspreadableToRestKeys]); + } + if (omitKeyType.flags & TypeFlags.Never) { return source; } @@ -8477,12 +8501,8 @@ namespace ts { return getTypeAliasInstantiation(omitTypeAlias, [source, omitKeyType]); } const members = createSymbolTable(); - for (const prop of getPropertiesOfType(source)) { - if (!isTypeAssignableTo(getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique), omitKeyType) - && !(getDeclarationModifierFlagsFromSymbol(prop) & (ModifierFlags.Private | ModifierFlags.Protected)) - && isSpreadableProperty(prop)) { - members.set(prop.escapedName, getSpreadSymbol(prop, /*readonly*/ false)); - } + for (const prop of spreadableProperties) { + members.set(prop.escapedName, getSpreadSymbol(prop, /*readonly*/ false)); } const result = createAnonymousType(symbol, members, emptyArray, emptyArray, getIndexInfosOfType(source)); result.objectFlags |= ObjectFlags.ObjectRestType; diff --git a/tests/baselines/reference/destructuringThisWithProperty.errors.txt b/tests/baselines/reference/destructuringThisWithProperty.errors.txt index 4e5186a3e3614..6f06529faf8b1 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.errors.txt +++ b/tests/baselines/reference/destructuringThisWithProperty.errors.txt @@ -1,13 +1,15 @@ tests/cases/compiler/destructuringThisWithProperty.ts(4,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/destructuringThisWithProperty.ts(16,15): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. +tests/cases/compiler/destructuringThisWithProperty.ts(16,15): error TS2339: Property 'bar' does not exist on type 'Omit'. tests/cases/compiler/destructuringThisWithProperty.ts(17,15): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. -tests/cases/compiler/destructuringThisWithProperty.ts(18,15): error TS2339: Property 'bar' does not exist on type '{}'. +tests/cases/compiler/destructuringThisWithProperty.ts(18,15): error TS2339: Property 'bar' does not exist on type 'Omit'. tests/cases/compiler/destructuringThisWithProperty.ts(19,15): error TS2339: Property 'bar' does not exist on type '{}'. +tests/cases/compiler/destructuringThisWithProperty.ts(31,11): error TS2339: Property 'bar' does not exist on type 'Omit'. tests/cases/compiler/destructuringThisWithProperty.ts(32,11): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. +tests/cases/compiler/destructuringThisWithProperty.ts(33,11): error TS2339: Property 'bar' does not exist on type 'Omit'. tests/cases/compiler/destructuringThisWithProperty.ts(34,11): error TS2339: Property 'bar' does not exist on type '{}'. -==== tests/cases/compiler/destructuringThisWithProperty.ts (7 errors) ==== +==== tests/cases/compiler/destructuringThisWithProperty.ts (9 errors) ==== class A { constructor(public foo: string) {} @@ -27,13 +29,13 @@ tests/cases/compiler/destructuringThisWithProperty.ts(34,11): error TS2339: Prop // "bar" should not be present in any of these. rest1.bar; ~~~ -!!! error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. +!!! error TS2339: Property 'bar' does not exist on type 'Omit'. rest2.bar; ~~~ !!! error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. rest3.bar; ~~~ -!!! error TS2339: Property 'bar' does not exist on type '{}'. +!!! error TS2339: Property 'bar' does not exist on type 'Omit'. rest4.bar; ~~~ !!! error TS2339: Property 'bar' does not exist on type '{}'. @@ -49,10 +51,14 @@ tests/cases/compiler/destructuringThisWithProperty.ts(34,11): error TS2339: Prop // Rest destructuring drops properties provided by getters. // "bar" should not be present in any of these. rest1.bar; + ~~~ +!!! error TS2339: Property 'bar' does not exist on type 'Omit'. 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'. rest4.bar; ~~~ !!! error TS2339: Property 'bar' does not exist on type '{}'. diff --git a/tests/baselines/reference/destructuringThisWithProperty.symbols b/tests/baselines/reference/destructuringThisWithProperty.symbols index d11afef6d3845..1e8ff71f19955 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.symbols +++ b/tests/baselines/reference/destructuringThisWithProperty.symbols @@ -84,17 +84,13 @@ function destructure(x: T) { // Rest destructuring drops properties provided by getters. // "bar" should not be present in any of these. rest1.bar; ->rest1.bar : Symbol(A.bar, Decl(destructuringThisWithProperty.ts, 1, 38)) >rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 23, 11)) ->bar : Symbol(A.bar, Decl(destructuringThisWithProperty.ts, 1, 38)) rest2.bar; >rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 24, 11)) rest3.bar; ->rest3.bar : Symbol(bar, Decl(destructuringThisWithProperty.ts, 1, 38)) >rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 25, 21)) ->bar : Symbol(bar, Decl(destructuringThisWithProperty.ts, 1, 38)) rest4.bar; >rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 26, 21)) diff --git a/tests/baselines/reference/destructuringThisWithProperty.types b/tests/baselines/reference/destructuringThisWithProperty.types index 50a50f3c9f2e8..fe2aa5de9b91e 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.types +++ b/tests/baselines/reference/destructuringThisWithProperty.types @@ -16,7 +16,7 @@ class A { >func : () => void const { ...rest1 } = this; ->rest1 : { foo: string; } +>rest1 : Omit >this : this const { ...rest2 } = this as A; @@ -27,7 +27,7 @@ class A { const { foo: _f1, ...rest3 } = this; >foo : any >_f1 : string ->rest3 : {} +>rest3 : Omit >this : this const { foo: _f2, ...rest4 } = this as A; @@ -41,7 +41,7 @@ class A { // "bar" should not be present in any of these. rest1.bar; >rest1.bar : any ->rest1 : { foo: string; } +>rest1 : Omit >bar : any rest2.bar; @@ -51,7 +51,7 @@ class A { rest3.bar; >rest3.bar : any ->rest3 : {} +>rest3 : Omit >bar : any rest4.bar; @@ -66,7 +66,7 @@ function destructure(x: T) { >x : T const { ...rest1 } = x; ->rest1 : T +>rest1 : Omit >x : T const { ...rest2 } = x as A; @@ -77,7 +77,7 @@ function destructure(x: T) { const { foo: _f1, ...rest3 } = x; >foo : any >_f1 : string ->rest3 : Omit +>rest3 : Omit >x : T const { foo: _f2, ...rest4 } = x as A; @@ -90,9 +90,9 @@ function destructure(x: T) { // Rest destructuring drops properties provided by getters. // "bar" should not be present in any of these. rest1.bar; ->rest1.bar : number ->rest1 : T ->bar : number +>rest1.bar : any +>rest1 : Omit +>bar : any rest2.bar; >rest2.bar : any @@ -100,9 +100,9 @@ function destructure(x: T) { >bar : any rest3.bar; ->rest3.bar : T["bar"] ->rest3 : Omit ->bar : T["bar"] +>rest3.bar : any +>rest3 : Omit +>bar : any rest4.bar; >rest4.bar : any From 7d0aa5cee613a014f8d1e0cec98c06280ce9c697 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 8 Dec 2021 19:27:38 -0800 Subject: [PATCH 5/9] Add tests for method --- .../destructuringThisWithProperty.errors.txt | 56 ++++++++++++---- .../destructuringThisWithProperty.js | 26 +++++--- .../destructuringThisWithProperty.symbols | 64 ++++++++++++------- .../destructuringThisWithProperty.types | 44 +++++++++++-- .../compiler/destructuringThisWithProperty.ts | 14 ++-- 5 files changed, 153 insertions(+), 51 deletions(-) diff --git a/tests/baselines/reference/destructuringThisWithProperty.errors.txt b/tests/baselines/reference/destructuringThisWithProperty.errors.txt index 6f06529faf8b1..c6a2141197b15 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.errors.txt +++ b/tests/baselines/reference/destructuringThisWithProperty.errors.txt @@ -1,15 +1,23 @@ tests/cases/compiler/destructuringThisWithProperty.ts(4,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/destructuringThisWithProperty.ts(16,15): error TS2339: Property 'bar' does not exist on type 'Omit'. -tests/cases/compiler/destructuringThisWithProperty.ts(17,15): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. -tests/cases/compiler/destructuringThisWithProperty.ts(18,15): error TS2339: Property 'bar' does not exist on type 'Omit'. -tests/cases/compiler/destructuringThisWithProperty.ts(19,15): error TS2339: Property 'bar' does not exist on type '{}'. -tests/cases/compiler/destructuringThisWithProperty.ts(31,11): error TS2339: Property 'bar' does not exist on type 'Omit'. -tests/cases/compiler/destructuringThisWithProperty.ts(32,11): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. -tests/cases/compiler/destructuringThisWithProperty.ts(33,11): error TS2339: Property 'bar' does not exist on type 'Omit'. -tests/cases/compiler/destructuringThisWithProperty.ts(34,11): error TS2339: Property 'bar' does not exist on type '{}'. +tests/cases/compiler/destructuringThisWithProperty.ts(14,15): error TS2339: Property 'bar' does not exist on type 'Omit'. +tests/cases/compiler/destructuringThisWithProperty.ts(15,15): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. +tests/cases/compiler/destructuringThisWithProperty.ts(16,15): error TS2339: Property 'bar' does not exist on type 'Omit'. +tests/cases/compiler/destructuringThisWithProperty.ts(17,15): error TS2339: Property 'bar' does not exist on type '{}'. +tests/cases/compiler/destructuringThisWithProperty.ts(19,15): error TS2339: Property 'func' does not exist on type 'Omit'. +tests/cases/compiler/destructuringThisWithProperty.ts(20,15): error TS2339: Property 'func' does not exist on type '{ foo: string; }'. +tests/cases/compiler/destructuringThisWithProperty.ts(21,15): error TS2339: Property 'func' does not exist on type 'Omit'. +tests/cases/compiler/destructuringThisWithProperty.ts(22,15): error TS2339: Property 'func' does not exist on type '{}'. +tests/cases/compiler/destructuringThisWithProperty.ts(32,11): error TS2339: Property 'bar' does not exist on type 'Omit'. +tests/cases/compiler/destructuringThisWithProperty.ts(33,11): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. +tests/cases/compiler/destructuringThisWithProperty.ts(34,11): error TS2339: Property 'bar' does not exist on type 'Omit'. +tests/cases/compiler/destructuringThisWithProperty.ts(35,11): error TS2339: Property 'bar' does not exist on type '{}'. +tests/cases/compiler/destructuringThisWithProperty.ts(37,11): error TS2339: Property 'func' does not exist on type 'Omit'. +tests/cases/compiler/destructuringThisWithProperty.ts(38,11): error TS2339: Property 'func' does not exist on type '{ foo: string; }'. +tests/cases/compiler/destructuringThisWithProperty.ts(39,11): error TS2339: Property 'func' does not exist on type 'Omit'. +tests/cases/compiler/destructuringThisWithProperty.ts(40,11): error TS2339: Property 'func' does not exist on type '{}'. -==== tests/cases/compiler/destructuringThisWithProperty.ts (9 errors) ==== +==== tests/cases/compiler/destructuringThisWithProperty.ts (17 errors) ==== class A { constructor(public foo: string) {} @@ -25,8 +33,6 @@ tests/cases/compiler/destructuringThisWithProperty.ts(34,11): error TS2339: Prop const { foo: _f1, ...rest3 } = this; const { foo: _f2, ...rest4 } = this as A; - // Rest destructuring drops properties provided by getters. - // "bar" should not be present in any of these. rest1.bar; ~~~ !!! error TS2339: Property 'bar' does not exist on type 'Omit'. @@ -39,6 +45,19 @@ tests/cases/compiler/destructuringThisWithProperty.ts(34,11): error TS2339: Prop rest4.bar; ~~~ !!! error TS2339: Property 'bar' does not exist on type '{}'. + + rest1.func; + ~~~~ +!!! error TS2339: Property 'func' does not exist on type 'Omit'. + 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'. + rest4.func; + ~~~~ +!!! error TS2339: Property 'func' does not exist on type '{}'. } } @@ -48,8 +67,6 @@ tests/cases/compiler/destructuringThisWithProperty.ts(34,11): error TS2339: Prop const { foo: _f1, ...rest3 } = x; const { foo: _f2, ...rest4 } = x as A; - // Rest destructuring drops properties provided by getters. - // "bar" should not be present in any of these. rest1.bar; ~~~ !!! error TS2339: Property 'bar' does not exist on type 'Omit'. @@ -62,5 +79,18 @@ tests/cases/compiler/destructuringThisWithProperty.ts(34,11): error TS2339: Prop rest4.bar; ~~~ !!! error TS2339: Property 'bar' does not exist on type '{}'. + + rest1.func; + ~~~~ +!!! error TS2339: Property 'func' does not exist on type 'Omit'. + 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'. + rest4.func; + ~~~~ +!!! error TS2339: Property 'func' does not exist on type '{}'. } \ No newline at end of file diff --git a/tests/baselines/reference/destructuringThisWithProperty.js b/tests/baselines/reference/destructuringThisWithProperty.js index e8d141b29f80d..d0d9e04d89e91 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.js +++ b/tests/baselines/reference/destructuringThisWithProperty.js @@ -12,12 +12,15 @@ class A { const { foo: _f1, ...rest3 } = this; const { foo: _f2, ...rest4 } = this as A; - // Rest destructuring drops properties provided by getters. - // "bar" should not be present in any of these. rest1.bar; rest2.bar; rest3.bar; rest4.bar; + + rest1.func; + rest2.func; + rest3.func; + rest4.func; } } @@ -27,12 +30,15 @@ function destructure(x: T) { const { foo: _f1, ...rest3 } = x; const { foo: _f2, ...rest4 } = x as A; - // Rest destructuring drops properties provided by getters. - // "bar" should not be present in any of these. rest1.bar; rest2.bar; rest3.bar; rest4.bar; + + rest1.func; + rest2.func; + rest3.func; + rest4.func; } @@ -64,12 +70,14 @@ var A = /** @class */ (function () { var rest2 = __rest(this, []); var _a = this, _f1 = _a.foo, rest3 = __rest(_a, ["foo"]); var _b = this, _f2 = _b.foo, rest4 = __rest(_b, ["foo"]); - // Rest destructuring drops properties provided by getters. - // "bar" should not be present in any of these. rest1.bar; rest2.bar; rest3.bar; rest4.bar; + rest1.func; + rest2.func; + rest3.func; + rest4.func; }; return A; }()); @@ -78,10 +86,12 @@ function destructure(x) { var rest2 = __rest(x, []); var _f1 = x.foo, rest3 = __rest(x, ["foo"]); var _a = x, _f2 = _a.foo, rest4 = __rest(_a, ["foo"]); - // Rest destructuring drops properties provided by getters. - // "bar" should not be present in any of these. rest1.bar; rest2.bar; rest3.bar; rest4.bar; + rest1.func; + rest2.func; + rest3.func; + rest4.func; } diff --git a/tests/baselines/reference/destructuringThisWithProperty.symbols b/tests/baselines/reference/destructuringThisWithProperty.symbols index 1e8ff71f19955..eb464c4e24685 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.symbols +++ b/tests/baselines/reference/destructuringThisWithProperty.symbols @@ -36,8 +36,6 @@ class A { >this : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) >A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) - // Rest destructuring drops properties provided by getters. - // "bar" should not be present in any of these. rest1.bar; >rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 8, 15)) @@ -49,50 +47,72 @@ class A { rest4.bar; >rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 11, 25)) + + rest1.func; +>rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 8, 15)) + + rest2.func; +>rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 9, 15)) + + rest3.func; +>rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 10, 25)) + + rest4.func; +>rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 11, 25)) } } function destructure(x: T) { ->destructure : Symbol(destructure, Decl(destructuringThisWithProperty.ts, 20, 1)) ->T : Symbol(T, Decl(destructuringThisWithProperty.ts, 22, 21)) +>destructure : Symbol(destructure, Decl(destructuringThisWithProperty.ts, 23, 1)) +>T : Symbol(T, Decl(destructuringThisWithProperty.ts, 25, 21)) >A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) ->x : Symbol(x, Decl(destructuringThisWithProperty.ts, 22, 34)) ->T : Symbol(T, Decl(destructuringThisWithProperty.ts, 22, 21)) +>x : Symbol(x, Decl(destructuringThisWithProperty.ts, 25, 34)) +>T : Symbol(T, Decl(destructuringThisWithProperty.ts, 25, 21)) const { ...rest1 } = x; ->rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 23, 11)) ->x : Symbol(x, Decl(destructuringThisWithProperty.ts, 22, 34)) +>rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 26, 11)) +>x : Symbol(x, Decl(destructuringThisWithProperty.ts, 25, 34)) const { ...rest2 } = x as A; ->rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 24, 11)) ->x : Symbol(x, Decl(destructuringThisWithProperty.ts, 22, 34)) +>rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 27, 11)) +>x : Symbol(x, Decl(destructuringThisWithProperty.ts, 25, 34)) >A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) const { foo: _f1, ...rest3 } = x; >foo : Symbol(A.foo, Decl(destructuringThisWithProperty.ts, 1, 16)) ->_f1 : Symbol(_f1, Decl(destructuringThisWithProperty.ts, 25, 11)) ->rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 25, 21)) ->x : Symbol(x, Decl(destructuringThisWithProperty.ts, 22, 34)) +>_f1 : Symbol(_f1, Decl(destructuringThisWithProperty.ts, 28, 11)) +>rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 28, 21)) +>x : Symbol(x, Decl(destructuringThisWithProperty.ts, 25, 34)) const { foo: _f2, ...rest4 } = x as A; >foo : Symbol(A.foo, Decl(destructuringThisWithProperty.ts, 1, 16)) ->_f2 : Symbol(_f2, Decl(destructuringThisWithProperty.ts, 26, 11)) ->rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 26, 21)) ->x : Symbol(x, Decl(destructuringThisWithProperty.ts, 22, 34)) +>_f2 : Symbol(_f2, Decl(destructuringThisWithProperty.ts, 29, 11)) +>rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 29, 21)) +>x : Symbol(x, Decl(destructuringThisWithProperty.ts, 25, 34)) >A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) - // Rest destructuring drops properties provided by getters. - // "bar" should not be present in any of these. rest1.bar; ->rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 23, 11)) +>rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 26, 11)) rest2.bar; ->rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 24, 11)) +>rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 27, 11)) rest3.bar; ->rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 25, 21)) +>rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 28, 21)) rest4.bar; ->rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 26, 21)) +>rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 29, 21)) + + rest1.func; +>rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 26, 11)) + + rest2.func; +>rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 27, 11)) + + rest3.func; +>rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 28, 21)) + + rest4.func; +>rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 29, 21)) } diff --git a/tests/baselines/reference/destructuringThisWithProperty.types b/tests/baselines/reference/destructuringThisWithProperty.types index fe2aa5de9b91e..8227dc54f47b4 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.types +++ b/tests/baselines/reference/destructuringThisWithProperty.types @@ -37,8 +37,6 @@ class A { >this as A : A >this : this - // Rest destructuring drops properties provided by getters. - // "bar" should not be present in any of these. rest1.bar; >rest1.bar : any >rest1 : Omit @@ -58,6 +56,26 @@ class A { >rest4.bar : any >rest4 : {} >bar : any + + rest1.func; +>rest1.func : any +>rest1 : Omit +>func : any + + rest2.func; +>rest2.func : any +>rest2 : { foo: string; } +>func : any + + rest3.func; +>rest3.func : any +>rest3 : Omit +>func : any + + rest4.func; +>rest4.func : any +>rest4 : {} +>func : any } } @@ -87,8 +105,6 @@ function destructure(x: T) { >x as A : A >x : T - // Rest destructuring drops properties provided by getters. - // "bar" should not be present in any of these. rest1.bar; >rest1.bar : any >rest1 : Omit @@ -108,5 +124,25 @@ function destructure(x: T) { >rest4.bar : any >rest4 : {} >bar : any + + rest1.func; +>rest1.func : any +>rest1 : Omit +>func : any + + rest2.func; +>rest2.func : any +>rest2 : { foo: string; } +>func : any + + rest3.func; +>rest3.func : any +>rest3 : Omit +>func : any + + rest4.func; +>rest4.func : any +>rest4 : {} +>func : any } diff --git a/tests/cases/compiler/destructuringThisWithProperty.ts b/tests/cases/compiler/destructuringThisWithProperty.ts index be33a519bd052..0db33e8e9daf8 100644 --- a/tests/cases/compiler/destructuringThisWithProperty.ts +++ b/tests/cases/compiler/destructuringThisWithProperty.ts @@ -11,12 +11,15 @@ class A { const { foo: _f1, ...rest3 } = this; const { foo: _f2, ...rest4 } = this as A; - // Rest destructuring drops properties provided by getters. - // "bar" should not be present in any of these. rest1.bar; rest2.bar; rest3.bar; rest4.bar; + + rest1.func; + rest2.func; + rest3.func; + rest4.func; } } @@ -26,10 +29,13 @@ function destructure(x: T) { const { foo: _f1, ...rest3 } = x; const { foo: _f2, ...rest4 } = x as A; - // Rest destructuring drops properties provided by getters. - // "bar" should not be present in any of these. rest1.bar; rest2.bar; rest3.bar; rest4.bar; + + rest1.func; + rest2.func; + rest3.func; + rest4.func; } From 5eb70f8d017b0dc864c4f3a458df7c5f96291f3f Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 8 Dec 2021 19:30:21 -0800 Subject: [PATCH 6/9] Rename test to better reflect result --- .../destructuringThisWithProperty.symbols | 118 ------------------ ...tructuringUnspreadableIntoRest.errors.txt} | 36 +++--- ...s => destructuringUnspreadableIntoRest.js} | 4 +- .../destructuringUnspreadableIntoRest.symbols | 118 ++++++++++++++++++ ...> destructuringUnspreadableIntoRest.types} | 2 +- ...s => destructuringUnspreadableIntoRest.ts} | 0 6 files changed, 139 insertions(+), 139 deletions(-) delete mode 100644 tests/baselines/reference/destructuringThisWithProperty.symbols rename tests/baselines/reference/{destructuringThisWithProperty.errors.txt => destructuringUnspreadableIntoRest.errors.txt} (51%) rename tests/baselines/reference/{destructuringThisWithProperty.js => destructuringUnspreadableIntoRest.js} (94%) create mode 100644 tests/baselines/reference/destructuringUnspreadableIntoRest.symbols rename tests/baselines/reference/{destructuringThisWithProperty.types => destructuringUnspreadableIntoRest.types} (91%) rename tests/cases/compiler/{destructuringThisWithProperty.ts => destructuringUnspreadableIntoRest.ts} (100%) diff --git a/tests/baselines/reference/destructuringThisWithProperty.symbols b/tests/baselines/reference/destructuringThisWithProperty.symbols deleted file mode 100644 index eb464c4e24685..0000000000000 --- a/tests/baselines/reference/destructuringThisWithProperty.symbols +++ /dev/null @@ -1,118 +0,0 @@ -=== tests/cases/compiler/destructuringThisWithProperty.ts === -class A { ->A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) - - constructor(public foo: string) {} ->foo : Symbol(A.foo, Decl(destructuringThisWithProperty.ts, 1, 16)) - - get bar(): number { ->bar : Symbol(A.bar, Decl(destructuringThisWithProperty.ts, 1, 38)) - - return 1; - } - - func() { ->func : Symbol(A.func, Decl(destructuringThisWithProperty.ts, 5, 5)) - - const { ...rest1 } = this; ->rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 8, 15)) ->this : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) - - const { ...rest2 } = this as A; ->rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 9, 15)) ->this : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) ->A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) - - const { foo: _f1, ...rest3 } = this; ->foo : Symbol(A.foo, Decl(destructuringThisWithProperty.ts, 1, 16)) ->_f1 : Symbol(_f1, Decl(destructuringThisWithProperty.ts, 10, 15)) ->rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 10, 25)) ->this : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) - - const { foo: _f2, ...rest4 } = this as A; ->foo : Symbol(A.foo, Decl(destructuringThisWithProperty.ts, 1, 16)) ->_f2 : Symbol(_f2, Decl(destructuringThisWithProperty.ts, 11, 15)) ->rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 11, 25)) ->this : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) ->A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) - - rest1.bar; ->rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 8, 15)) - - rest2.bar; ->rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 9, 15)) - - rest3.bar; ->rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 10, 25)) - - rest4.bar; ->rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 11, 25)) - - rest1.func; ->rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 8, 15)) - - rest2.func; ->rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 9, 15)) - - rest3.func; ->rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 10, 25)) - - rest4.func; ->rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 11, 25)) - } -} - -function destructure(x: T) { ->destructure : Symbol(destructure, Decl(destructuringThisWithProperty.ts, 23, 1)) ->T : Symbol(T, Decl(destructuringThisWithProperty.ts, 25, 21)) ->A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) ->x : Symbol(x, Decl(destructuringThisWithProperty.ts, 25, 34)) ->T : Symbol(T, Decl(destructuringThisWithProperty.ts, 25, 21)) - - const { ...rest1 } = x; ->rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 26, 11)) ->x : Symbol(x, Decl(destructuringThisWithProperty.ts, 25, 34)) - - const { ...rest2 } = x as A; ->rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 27, 11)) ->x : Symbol(x, Decl(destructuringThisWithProperty.ts, 25, 34)) ->A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) - - const { foo: _f1, ...rest3 } = x; ->foo : Symbol(A.foo, Decl(destructuringThisWithProperty.ts, 1, 16)) ->_f1 : Symbol(_f1, Decl(destructuringThisWithProperty.ts, 28, 11)) ->rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 28, 21)) ->x : Symbol(x, Decl(destructuringThisWithProperty.ts, 25, 34)) - - const { foo: _f2, ...rest4 } = x as A; ->foo : Symbol(A.foo, Decl(destructuringThisWithProperty.ts, 1, 16)) ->_f2 : Symbol(_f2, Decl(destructuringThisWithProperty.ts, 29, 11)) ->rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 29, 21)) ->x : Symbol(x, Decl(destructuringThisWithProperty.ts, 25, 34)) ->A : Symbol(A, Decl(destructuringThisWithProperty.ts, 0, 0)) - - rest1.bar; ->rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 26, 11)) - - rest2.bar; ->rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 27, 11)) - - rest3.bar; ->rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 28, 21)) - - rest4.bar; ->rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 29, 21)) - - rest1.func; ->rest1 : Symbol(rest1, Decl(destructuringThisWithProperty.ts, 26, 11)) - - rest2.func; ->rest2 : Symbol(rest2, Decl(destructuringThisWithProperty.ts, 27, 11)) - - rest3.func; ->rest3 : Symbol(rest3, Decl(destructuringThisWithProperty.ts, 28, 21)) - - rest4.func; ->rest4 : Symbol(rest4, Decl(destructuringThisWithProperty.ts, 29, 21)) -} - diff --git a/tests/baselines/reference/destructuringThisWithProperty.errors.txt b/tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt similarity index 51% rename from tests/baselines/reference/destructuringThisWithProperty.errors.txt rename to tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt index c6a2141197b15..c8a5a5b8b2875 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.errors.txt +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt @@ -1,23 +1,23 @@ -tests/cases/compiler/destructuringThisWithProperty.ts(4,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/destructuringThisWithProperty.ts(14,15): error TS2339: Property 'bar' does not exist on type 'Omit'. -tests/cases/compiler/destructuringThisWithProperty.ts(15,15): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. -tests/cases/compiler/destructuringThisWithProperty.ts(16,15): error TS2339: Property 'bar' does not exist on type 'Omit'. -tests/cases/compiler/destructuringThisWithProperty.ts(17,15): error TS2339: Property 'bar' does not exist on type '{}'. -tests/cases/compiler/destructuringThisWithProperty.ts(19,15): error TS2339: Property 'func' does not exist on type 'Omit'. -tests/cases/compiler/destructuringThisWithProperty.ts(20,15): error TS2339: Property 'func' does not exist on type '{ foo: string; }'. -tests/cases/compiler/destructuringThisWithProperty.ts(21,15): error TS2339: Property 'func' does not exist on type 'Omit'. -tests/cases/compiler/destructuringThisWithProperty.ts(22,15): error TS2339: Property 'func' does not exist on type '{}'. -tests/cases/compiler/destructuringThisWithProperty.ts(32,11): error TS2339: Property 'bar' does not exist on type 'Omit'. -tests/cases/compiler/destructuringThisWithProperty.ts(33,11): error TS2339: Property 'bar' does not exist on type '{ foo: string; }'. -tests/cases/compiler/destructuringThisWithProperty.ts(34,11): error TS2339: Property 'bar' does not exist on type 'Omit'. -tests/cases/compiler/destructuringThisWithProperty.ts(35,11): error TS2339: Property 'bar' does not exist on type '{}'. -tests/cases/compiler/destructuringThisWithProperty.ts(37,11): error TS2339: Property 'func' does not exist on type 'Omit'. -tests/cases/compiler/destructuringThisWithProperty.ts(38,11): error TS2339: Property 'func' does not exist on type '{ foo: string; }'. -tests/cases/compiler/destructuringThisWithProperty.ts(39,11): error TS2339: Property 'func' does not exist on type 'Omit'. -tests/cases/compiler/destructuringThisWithProperty.ts(40,11): error TS2339: Property 'func' does not exist on type '{}'. +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'. +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'. +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'. +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'. +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'. +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'. +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'. +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'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(40,11): error TS2339: Property 'func' does not exist on type '{}'. -==== tests/cases/compiler/destructuringThisWithProperty.ts (17 errors) ==== +==== tests/cases/compiler/destructuringUnspreadableIntoRest.ts (17 errors) ==== class A { constructor(public foo: string) {} diff --git a/tests/baselines/reference/destructuringThisWithProperty.js b/tests/baselines/reference/destructuringUnspreadableIntoRest.js similarity index 94% rename from tests/baselines/reference/destructuringThisWithProperty.js rename to tests/baselines/reference/destructuringUnspreadableIntoRest.js index d0d9e04d89e91..d78c9de0f4644 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.js +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.js @@ -1,4 +1,4 @@ -//// [destructuringThisWithProperty.ts] +//// [destructuringUnspreadableIntoRest.ts] class A { constructor(public foo: string) {} @@ -42,7 +42,7 @@ function destructure(x: T) { } -//// [destructuringThisWithProperty.js] +//// [destructuringUnspreadableIntoRest.js] var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) diff --git a/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols b/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols new file mode 100644 index 0000000000000..d821a22045ed5 --- /dev/null +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols @@ -0,0 +1,118 @@ +=== tests/cases/compiler/destructuringUnspreadableIntoRest.ts === +class A { +>A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) + + constructor(public foo: string) {} +>foo : Symbol(A.foo, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) + + get bar(): number { +>bar : Symbol(A.bar, Decl(destructuringUnspreadableIntoRest.ts, 1, 38)) + + return 1; + } + + func() { +>func : Symbol(A.func, Decl(destructuringUnspreadableIntoRest.ts, 5, 5)) + + const { ...rest1 } = this; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 8, 15)) +>this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) + + const { ...rest2 } = this as A; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 9, 15)) +>this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) +>A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) + + const { foo: _f1, ...rest3 } = this; +>foo : Symbol(A.foo, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>_f1 : Symbol(_f1, Decl(destructuringUnspreadableIntoRest.ts, 10, 15)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 10, 25)) +>this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) + + const { foo: _f2, ...rest4 } = this as A; +>foo : Symbol(A.foo, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>_f2 : Symbol(_f2, Decl(destructuringUnspreadableIntoRest.ts, 11, 15)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 11, 25)) +>this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) +>A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) + + rest1.bar; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 8, 15)) + + rest2.bar; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 9, 15)) + + rest3.bar; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 10, 25)) + + rest4.bar; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 11, 25)) + + rest1.func; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 8, 15)) + + rest2.func; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 9, 15)) + + rest3.func; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 10, 25)) + + rest4.func; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 11, 25)) + } +} + +function destructure(x: T) { +>destructure : Symbol(destructure, Decl(destructuringUnspreadableIntoRest.ts, 23, 1)) +>T : Symbol(T, Decl(destructuringUnspreadableIntoRest.ts, 25, 21)) +>A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 25, 34)) +>T : Symbol(T, Decl(destructuringUnspreadableIntoRest.ts, 25, 21)) + + const { ...rest1 } = x; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 26, 11)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 25, 34)) + + const { ...rest2 } = x as A; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 27, 11)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 25, 34)) +>A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) + + const { foo: _f1, ...rest3 } = x; +>foo : Symbol(A.foo, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>_f1 : Symbol(_f1, Decl(destructuringUnspreadableIntoRest.ts, 28, 11)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 28, 21)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 25, 34)) + + const { foo: _f2, ...rest4 } = x as A; +>foo : Symbol(A.foo, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>_f2 : Symbol(_f2, Decl(destructuringUnspreadableIntoRest.ts, 29, 11)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 29, 21)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 25, 34)) +>A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) + + rest1.bar; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 26, 11)) + + rest2.bar; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 27, 11)) + + rest3.bar; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 28, 21)) + + rest4.bar; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 29, 21)) + + rest1.func; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 26, 11)) + + rest2.func; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 27, 11)) + + rest3.func; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 28, 21)) + + rest4.func; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 29, 21)) +} + diff --git a/tests/baselines/reference/destructuringThisWithProperty.types b/tests/baselines/reference/destructuringUnspreadableIntoRest.types similarity index 91% rename from tests/baselines/reference/destructuringThisWithProperty.types rename to tests/baselines/reference/destructuringUnspreadableIntoRest.types index 8227dc54f47b4..26798c3d6c6ef 100644 --- a/tests/baselines/reference/destructuringThisWithProperty.types +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.types @@ -1,4 +1,4 @@ -=== tests/cases/compiler/destructuringThisWithProperty.ts === +=== tests/cases/compiler/destructuringUnspreadableIntoRest.ts === class A { >A : A diff --git a/tests/cases/compiler/destructuringThisWithProperty.ts b/tests/cases/compiler/destructuringUnspreadableIntoRest.ts similarity index 100% rename from tests/cases/compiler/destructuringThisWithProperty.ts rename to tests/cases/compiler/destructuringUnspreadableIntoRest.ts From d45768e9ee349698238a8f8a6d1d5935294b94e1 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 8 Dec 2021 19:41:25 -0800 Subject: [PATCH 7/9] Test a setter --- ...structuringUnspreadableIntoRest.errors.txt | 185 +++++++++------ .../destructuringUnspreadableIntoRest.js | 119 ++++++---- .../destructuringUnspreadableIntoRest.symbols | 162 +++++++------ .../destructuringUnspreadableIntoRest.types | 212 +++++++++++------- .../destructuringUnspreadableIntoRest.ts | 66 +++--- 5 files changed, 446 insertions(+), 298 deletions(-) diff --git a/tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt b/tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt index c8a5a5b8b2875..2268ea0d78ac9 100644 --- a/tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt @@ -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'. -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'. -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'. -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'. -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'. -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'. -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'. -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'. -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'. +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'. +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'. +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'. +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'. +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'. +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'. +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'. +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'. +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'. +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'. +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'. +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'. - 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'. - rest4.bar; - ~~~ -!!! error TS2339: Property 'bar' does not exist on type '{}'. + rest1.getter; + ~~~~~~ +!!! error TS2339: Property 'getter' does not exist on type 'Omit'. + 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'. + rest4.getter; + ~~~~~~ +!!! error TS2339: Property 'getter' does not exist on type '{}'. - rest1.func; - ~~~~ -!!! error TS2339: Property 'func' does not exist on type 'Omit'. - 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'. - rest4.func; - ~~~~ -!!! error TS2339: Property 'func' does not exist on type '{}'. + rest1.setter; + ~~~~~~ +!!! error TS2339: Property 'setter' does not exist on type 'Omit'. + 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'. + rest4.setter; + ~~~~~~ +!!! error TS2339: Property 'setter' does not exist on type '{}'. + + rest1.method; + ~~~~~~ +!!! error TS2339: Property 'method' does not exist on type 'Omit'. + 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'. + rest4.method; + ~~~~~~ +!!! error TS2339: Property 'method' does not exist on type '{}'. } } function destructure(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'. + 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'. + rest4.getter; + ~~~~~~ +!!! error TS2339: Property 'getter' does not exist on type '{}'. - rest1.bar; - ~~~ -!!! error TS2339: Property 'bar' does not exist on type 'Omit'. - 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'. - rest4.bar; - ~~~ -!!! error TS2339: Property 'bar' does not exist on type '{}'. + rest1.setter; + ~~~~~~ +!!! error TS2339: Property 'setter' does not exist on type 'Omit'. + 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'. + rest4.setter; + ~~~~~~ +!!! error TS2339: Property 'setter' does not exist on type '{}'. - rest1.func; - ~~~~ -!!! error TS2339: Property 'func' does not exist on type 'Omit'. - 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'. - rest4.func; - ~~~~ -!!! error TS2339: Property 'func' does not exist on type '{}'. + rest1.method; + ~~~~~~ +!!! error TS2339: Property 'method' does not exist on type 'Omit'. + 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'. + rest4.method; + ~~~~~~ +!!! error TS2339: Property 'method' does not exist on type '{}'. } \ No newline at end of file diff --git a/tests/baselines/reference/destructuringUnspreadableIntoRest.js b/tests/baselines/reference/destructuringUnspreadableIntoRest.js index d78c9de0f4644..4d14cd72ddbbb 100644 --- a/tests/baselines/reference/destructuringUnspreadableIntoRest.js +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.js @@ -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(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; } @@ -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; } diff --git a/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols b/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols index d821a22045ed5..69321ce50b513 100644 --- a/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols @@ -2,117 +2,145 @@ class A { >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) - constructor(public foo: string) {} ->foo : Symbol(A.foo, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) + constructor(public normal: string) {} +>normal : Symbol(A.normal, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) - get bar(): number { ->bar : Symbol(A.bar, Decl(destructuringUnspreadableIntoRest.ts, 1, 38)) + get getter(): number { +>getter : Symbol(A.getter, Decl(destructuringUnspreadableIntoRest.ts, 1, 41)) return 1; } - func() { ->func : Symbol(A.func, Decl(destructuringUnspreadableIntoRest.ts, 5, 5)) + set setter(_v: number) {} +>setter : Symbol(A.setter, Decl(destructuringUnspreadableIntoRest.ts, 5, 5)) +>_v : Symbol(_v, Decl(destructuringUnspreadableIntoRest.ts, 7, 15)) + + method() { +>method : Symbol(A.method, Decl(destructuringUnspreadableIntoRest.ts, 7, 29)) const { ...rest1 } = this; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 8, 15)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 10, 15)) >this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) const { ...rest2 } = this as A; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 9, 15)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 11, 15)) >this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) - const { foo: _f1, ...rest3 } = this; ->foo : Symbol(A.foo, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->_f1 : Symbol(_f1, Decl(destructuringUnspreadableIntoRest.ts, 10, 15)) ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 10, 25)) + const { normal: _1, ...rest3 } = this; +>normal : Symbol(A.normal, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>_1 : Symbol(_1, Decl(destructuringUnspreadableIntoRest.ts, 12, 15)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 12, 27)) >this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) - const { foo: _f2, ...rest4 } = this as A; ->foo : Symbol(A.foo, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->_f2 : Symbol(_f2, Decl(destructuringUnspreadableIntoRest.ts, 11, 15)) ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 11, 25)) + const { normal: _2, ...rest4 } = this as A; +>normal : Symbol(A.normal, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>_2 : Symbol(_2, Decl(destructuringUnspreadableIntoRest.ts, 13, 15)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 13, 27)) >this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) - rest1.bar; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 8, 15)) + rest1.getter; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 10, 15)) + + rest2.getter; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 11, 15)) + + rest3.getter; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 12, 27)) + + rest4.getter; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 13, 27)) + + rest1.setter; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 10, 15)) - rest2.bar; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 9, 15)) + rest2.setter; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 11, 15)) - rest3.bar; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 10, 25)) + rest3.setter; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 12, 27)) - rest4.bar; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 11, 25)) + rest4.setter; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 13, 27)) - rest1.func; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 8, 15)) + rest1.method; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 10, 15)) - rest2.func; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 9, 15)) + rest2.method; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 11, 15)) - rest3.func; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 10, 25)) + rest3.method; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 12, 27)) - rest4.func; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 11, 25)) + rest4.method; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 13, 27)) } } function destructure(x: T) { ->destructure : Symbol(destructure, Decl(destructuringUnspreadableIntoRest.ts, 23, 1)) ->T : Symbol(T, Decl(destructuringUnspreadableIntoRest.ts, 25, 21)) +>destructure : Symbol(destructure, Decl(destructuringUnspreadableIntoRest.ts, 30, 1)) +>T : Symbol(T, Decl(destructuringUnspreadableIntoRest.ts, 32, 21)) >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) ->x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 25, 34)) ->T : Symbol(T, Decl(destructuringUnspreadableIntoRest.ts, 25, 21)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 32, 34)) +>T : Symbol(T, Decl(destructuringUnspreadableIntoRest.ts, 32, 21)) const { ...rest1 } = x; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 26, 11)) ->x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 25, 34)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 33, 11)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 32, 34)) const { ...rest2 } = x as A; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 27, 11)) ->x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 25, 34)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 34, 11)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 32, 34)) >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) - const { foo: _f1, ...rest3 } = x; ->foo : Symbol(A.foo, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->_f1 : Symbol(_f1, Decl(destructuringUnspreadableIntoRest.ts, 28, 11)) ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 28, 21)) ->x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 25, 34)) - - const { foo: _f2, ...rest4 } = x as A; ->foo : Symbol(A.foo, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->_f2 : Symbol(_f2, Decl(destructuringUnspreadableIntoRest.ts, 29, 11)) ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 29, 21)) ->x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 25, 34)) + const { normal: _1, ...rest3 } = x; +>normal : Symbol(A.normal, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>_1 : Symbol(_1, Decl(destructuringUnspreadableIntoRest.ts, 35, 11)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 35, 23)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 32, 34)) + + const { normal: _2, ...rest4 } = x as A; +>normal : Symbol(A.normal, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>_2 : Symbol(_2, Decl(destructuringUnspreadableIntoRest.ts, 36, 11)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 36, 23)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 32, 34)) >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) - rest1.bar; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 26, 11)) + rest1.getter; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 33, 11)) + + rest2.getter; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 34, 11)) + + rest3.getter; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 35, 23)) + + rest4.getter; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 36, 23)) + + rest1.setter; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 33, 11)) - rest2.bar; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 27, 11)) + rest2.setter; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 34, 11)) - rest3.bar; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 28, 21)) + rest3.setter; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 35, 23)) - rest4.bar; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 29, 21)) + rest4.setter; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 36, 23)) - rest1.func; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 26, 11)) + rest1.method; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 33, 11)) - rest2.func; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 27, 11)) + rest2.method; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 34, 11)) - rest3.func; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 28, 21)) + rest3.method; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 35, 23)) - rest4.func; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 29, 21)) + rest4.method; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 36, 23)) } diff --git a/tests/baselines/reference/destructuringUnspreadableIntoRest.types b/tests/baselines/reference/destructuringUnspreadableIntoRest.types index 26798c3d6c6ef..d98edbac75620 100644 --- a/tests/baselines/reference/destructuringUnspreadableIntoRest.types +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.types @@ -2,80 +2,104 @@ class A { >A : A - constructor(public foo: string) {} ->foo : string + constructor(public normal: string) {} +>normal : string - get bar(): number { ->bar : number + get getter(): number { +>getter : number return 1; >1 : 1 } - func() { ->func : () => void + set setter(_v: number) {} +>setter : number +>_v : number + + method() { +>method : () => void const { ...rest1 } = this; ->rest1 : Omit +>rest1 : Omit >this : this const { ...rest2 } = this as A; ->rest2 : { foo: string; } +>rest2 : { normal: string; } >this as A : A >this : this - const { foo: _f1, ...rest3 } = this; ->foo : any ->_f1 : string ->rest3 : Omit + const { normal: _1, ...rest3 } = this; +>normal : any +>_1 : string +>rest3 : Omit >this : this - const { foo: _f2, ...rest4 } = this as A; ->foo : any ->_f2 : string + const { normal: _2, ...rest4 } = this as A; +>normal : any +>_2 : string >rest4 : {} >this as A : A >this : this - rest1.bar; ->rest1.bar : any ->rest1 : Omit ->bar : any + rest1.getter; +>rest1.getter : any +>rest1 : Omit +>getter : any + + rest2.getter; +>rest2.getter : any +>rest2 : { normal: string; } +>getter : any + + rest3.getter; +>rest3.getter : any +>rest3 : Omit +>getter : any + + rest4.getter; +>rest4.getter : any +>rest4 : {} +>getter : any + + rest1.setter; +>rest1.setter : any +>rest1 : Omit +>setter : any - rest2.bar; ->rest2.bar : any ->rest2 : { foo: string; } ->bar : any + rest2.setter; +>rest2.setter : any +>rest2 : { normal: string; } +>setter : any - rest3.bar; ->rest3.bar : any ->rest3 : Omit ->bar : any + rest3.setter; +>rest3.setter : any +>rest3 : Omit +>setter : any - rest4.bar; ->rest4.bar : any + rest4.setter; +>rest4.setter : any >rest4 : {} ->bar : any +>setter : any - rest1.func; ->rest1.func : any ->rest1 : Omit ->func : any + rest1.method; +>rest1.method : any +>rest1 : Omit +>method : any - rest2.func; ->rest2.func : any ->rest2 : { foo: string; } ->func : any + rest2.method; +>rest2.method : any +>rest2 : { normal: string; } +>method : any - rest3.func; ->rest3.func : any ->rest3 : Omit ->func : any + rest3.method; +>rest3.method : any +>rest3 : Omit +>method : any - rest4.func; ->rest4.func : any + rest4.method; +>rest4.method : any >rest4 : {} ->func : any +>method : any } } @@ -84,65 +108,85 @@ function destructure(x: T) { >x : T const { ...rest1 } = x; ->rest1 : Omit +>rest1 : Omit >x : T const { ...rest2 } = x as A; ->rest2 : { foo: string; } +>rest2 : { normal: string; } >x as A : A >x : T - const { foo: _f1, ...rest3 } = x; ->foo : any ->_f1 : string ->rest3 : Omit + const { normal: _1, ...rest3 } = x; +>normal : any +>_1 : string +>rest3 : Omit >x : T - const { foo: _f2, ...rest4 } = x as A; ->foo : any ->_f2 : string + const { normal: _2, ...rest4 } = x as A; +>normal : any +>_2 : string >rest4 : {} >x as A : A >x : T - rest1.bar; ->rest1.bar : any ->rest1 : Omit ->bar : any + rest1.getter; +>rest1.getter : any +>rest1 : Omit +>getter : any + + rest2.getter; +>rest2.getter : any +>rest2 : { normal: string; } +>getter : any + + rest3.getter; +>rest3.getter : any +>rest3 : Omit +>getter : any + + rest4.getter; +>rest4.getter : any +>rest4 : {} +>getter : any + + rest1.setter; +>rest1.setter : any +>rest1 : Omit +>setter : any - rest2.bar; ->rest2.bar : any ->rest2 : { foo: string; } ->bar : any + rest2.setter; +>rest2.setter : any +>rest2 : { normal: string; } +>setter : any - rest3.bar; ->rest3.bar : any ->rest3 : Omit ->bar : any + rest3.setter; +>rest3.setter : any +>rest3 : Omit +>setter : any - rest4.bar; ->rest4.bar : any + rest4.setter; +>rest4.setter : any >rest4 : {} ->bar : any +>setter : any - rest1.func; ->rest1.func : any ->rest1 : Omit ->func : any + rest1.method; +>rest1.method : any +>rest1 : Omit +>method : any - rest2.func; ->rest2.func : any ->rest2 : { foo: string; } ->func : any + rest2.method; +>rest2.method : any +>rest2 : { normal: string; } +>method : any - rest3.func; ->rest3.func : any ->rest3 : Omit ->func : any + rest3.method; +>rest3.method : any +>rest3 : Omit +>method : any - rest4.func; ->rest4.func : any + rest4.method; +>rest4.method : any >rest4 : {} ->func : any +>method : any } diff --git a/tests/cases/compiler/destructuringUnspreadableIntoRest.ts b/tests/cases/compiler/destructuringUnspreadableIntoRest.ts index 0db33e8e9daf8..27ad0a0085b94 100644 --- a/tests/cases/compiler/destructuringUnspreadableIntoRest.ts +++ b/tests/cases/compiler/destructuringUnspreadableIntoRest.ts @@ -1,41 +1,53 @@ 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; - - rest1.bar; - rest2.bar; - rest3.bar; - rest4.bar; - - rest1.func; - rest2.func; - rest3.func; - rest4.func; + const { normal: _1, ...rest3 } = this; + const { normal: _2, ...rest4 } = this as A; + + 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(x: T) { const { ...rest1 } = x; const { ...rest2 } = x as A; - const { foo: _f1, ...rest3 } = x; - const { foo: _f2, ...rest4 } = x as A; - - rest1.bar; - rest2.bar; - rest3.bar; - rest4.bar; - - rest1.func; - rest2.func; - rest3.func; - rest4.func; + const { normal: _1, ...rest3 } = x; + const { normal: _2, ...rest4 } = x as A; + + rest1.getter; + rest2.getter; + rest3.getter; + rest4.getter; + + rest1.setter; + rest2.setter; + rest3.setter; + rest4.setter; + + rest1.method; + rest2.method; + rest3.method; + rest4.method; } From f2bb9b778ee35d18c8a4edc25100b6c5e6ed04e5 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 8 Dec 2021 20:03:30 -0800 Subject: [PATCH 8/9] Test all different possibilities --- ...structuringUnspreadableIntoRest.errors.txt | 157 ++++++++++----- .../destructuringUnspreadableIntoRest.js | 103 ++++++---- .../destructuringUnspreadableIntoRest.symbols | 188 ++++++++++++------ .../destructuringUnspreadableIntoRest.types | 146 +++++++++++--- .../destructuringUnspreadableIntoRest.ts | 42 +++- 5 files changed, 446 insertions(+), 190 deletions(-) diff --git a/tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt b/tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt index 2268ea0d78ac9..57c534c24017c 100644 --- a/tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt @@ -1,60 +1,91 @@ -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(4,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -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'. -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'. -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'. -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'. -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'. -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'. -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'. -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'. -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'. -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'. -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'. -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'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(52,11): error TS2339: Property 'method' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(21,15): error TS2339: Property 'publicProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(22,15): error TS2339: Property 'publicProp' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(24,15): error TS2339: Property 'privateProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(25,15): error TS2339: Property 'privateProp' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(26,15): error TS2339: Property 'privateProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(27,15): error TS2339: Property 'privateProp' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(29,15): error TS2339: Property 'getter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(30,15): error TS2339: Property 'getter' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(31,15): error TS2339: Property 'getter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(32,15): error TS2339: Property 'getter' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(34,15): error TS2339: Property 'setter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(35,15): error TS2339: Property 'setter' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(36,15): error TS2339: Property 'setter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(37,15): error TS2339: Property 'setter' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(39,15): error TS2339: Property 'method' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(40,15): error TS2339: Property 'method' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(41,15): error TS2339: Property 'method' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(42,15): error TS2339: Property 'method' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(54,11): error TS2339: Property 'publicProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(55,11): error TS2339: Property 'publicProp' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(57,11): error TS2339: Property 'privateProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(58,11): error TS2339: Property 'privateProp' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(59,11): error TS2339: Property 'privateProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(60,11): error TS2339: Property 'privateProp' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(62,11): error TS2339: Property 'getter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(63,11): error TS2339: Property 'getter' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(64,11): error TS2339: Property 'getter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(65,11): error TS2339: Property 'getter' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(67,11): error TS2339: Property 'setter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(68,11): error TS2339: Property 'setter' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(69,11): error TS2339: Property 'setter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(70,11): error TS2339: Property 'setter' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(72,11): error TS2339: Property 'method' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(73,11): error TS2339: Property 'method' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(74,11): error TS2339: Property 'method' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(75,11): error TS2339: Property 'method' does not exist on type '{}'. -==== tests/cases/compiler/destructuringUnspreadableIntoRest.ts (26 errors) ==== +==== tests/cases/compiler/destructuringUnspreadableIntoRest.ts (36 errors) ==== class A { - constructor(public normal: string) {} + constructor( + public publicProp: string, + private privateProp: string, + ) {} get getter(): number { - ~~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. return 1; } 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 { normal: _1, ...rest3 } = this; - const { normal: _2, ...rest4 } = this as A; + 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; + ~~~~~~~~~~ +!!! error TS2339: Property 'publicProp' does not exist on type 'Omit'. + rest4.publicProp; + ~~~~~~~~~~ +!!! error TS2339: Property 'publicProp' does not exist on type '{}'. + + rest1.privateProp; + ~~~~~~~~~~~ +!!! error TS2339: Property 'privateProp' does not exist on type 'Omit'. + rest2.privateProp; + ~~~~~~~~~~~ +!!! error TS2339: Property 'privateProp' does not exist on type '{ publicProp: string; }'. + rest3.privateProp; + ~~~~~~~~~~~ +!!! error TS2339: Property 'privateProp' does not exist on type 'Omit'. + rest4.privateProp; + ~~~~~~~~~~~ +!!! error TS2339: Property 'privateProp' does not exist on type '{}'. rest1.getter; ~~~~~~ !!! error TS2339: Property 'getter' does not exist on type 'Omit'. rest2.getter; ~~~~~~ -!!! error TS2339: Property 'getter' does not exist on type '{ normal: string; }'. +!!! error TS2339: Property 'getter' does not exist on type '{ publicProp: string; }'. rest3.getter; ~~~~~~ -!!! error TS2339: Property 'getter' does not exist on type 'Omit'. +!!! error TS2339: Property 'getter' does not exist on type 'Omit'. rest4.getter; ~~~~~~ !!! error TS2339: Property 'getter' does not exist on type '{}'. @@ -64,10 +95,10 @@ tests/cases/compiler/destructuringUnspreadableIntoRest.ts(52,11): error TS2339: !!! error TS2339: Property 'setter' does not exist on type 'Omit'. rest2.setter; ~~~~~~ -!!! error TS2339: Property 'setter' does not exist on type '{ normal: string; }'. +!!! error TS2339: Property 'setter' does not exist on type '{ publicProp: string; }'. rest3.setter; ~~~~~~ -!!! error TS2339: Property 'setter' does not exist on type 'Omit'. +!!! error TS2339: Property 'setter' does not exist on type 'Omit'. rest4.setter; ~~~~~~ !!! error TS2339: Property 'setter' does not exist on type '{}'. @@ -77,10 +108,10 @@ tests/cases/compiler/destructuringUnspreadableIntoRest.ts(52,11): error TS2339: !!! error TS2339: Property 'method' does not exist on type 'Omit'. rest2.method; ~~~~~~ -!!! error TS2339: Property 'method' does not exist on type '{ normal: string; }'. +!!! error TS2339: Property 'method' does not exist on type '{ publicProp: string; }'. rest3.method; ~~~~~~ -!!! error TS2339: Property 'method' does not exist on type 'Omit'. +!!! error TS2339: Property 'method' does not exist on type 'Omit'. rest4.method; ~~~~~~ !!! error TS2339: Property 'method' does not exist on type '{}'. @@ -88,20 +119,42 @@ tests/cases/compiler/destructuringUnspreadableIntoRest.ts(52,11): error TS2339: } function destructure(x: T) { - const { ...rest1 } = x; - const { ...rest2 } = x as A; - const { normal: _1, ...rest3 } = x; - const { normal: _2, ...rest4 } = x as A; + 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; + ~~~~~~~~~~ +!!! error TS2339: Property 'publicProp' does not exist on type 'Omit'. + rest4.publicProp; + ~~~~~~~~~~ +!!! error TS2339: Property 'publicProp' does not exist on type '{}'. + + rest1.privateProp; + ~~~~~~~~~~~ +!!! error TS2339: Property 'privateProp' does not exist on type 'Omit'. + rest2.privateProp; + ~~~~~~~~~~~ +!!! error TS2339: Property 'privateProp' does not exist on type '{ publicProp: string; }'. + rest3.privateProp; + ~~~~~~~~~~~ +!!! error TS2339: Property 'privateProp' does not exist on type 'Omit'. + rest4.privateProp; + ~~~~~~~~~~~ +!!! error TS2339: Property 'privateProp' does not exist on type '{}'. rest1.getter; ~~~~~~ !!! error TS2339: Property 'getter' does not exist on type 'Omit'. rest2.getter; ~~~~~~ -!!! error TS2339: Property 'getter' does not exist on type '{ normal: string; }'. +!!! error TS2339: Property 'getter' does not exist on type '{ publicProp: string; }'. rest3.getter; ~~~~~~ -!!! error TS2339: Property 'getter' does not exist on type 'Omit'. +!!! error TS2339: Property 'getter' does not exist on type 'Omit'. rest4.getter; ~~~~~~ !!! error TS2339: Property 'getter' does not exist on type '{}'. @@ -111,10 +164,10 @@ tests/cases/compiler/destructuringUnspreadableIntoRest.ts(52,11): error TS2339: !!! error TS2339: Property 'setter' does not exist on type 'Omit'. rest2.setter; ~~~~~~ -!!! error TS2339: Property 'setter' does not exist on type '{ normal: string; }'. +!!! error TS2339: Property 'setter' does not exist on type '{ publicProp: string; }'. rest3.setter; ~~~~~~ -!!! error TS2339: Property 'setter' does not exist on type 'Omit'. +!!! error TS2339: Property 'setter' does not exist on type 'Omit'. rest4.setter; ~~~~~~ !!! error TS2339: Property 'setter' does not exist on type '{}'. @@ -124,10 +177,10 @@ tests/cases/compiler/destructuringUnspreadableIntoRest.ts(52,11): error TS2339: !!! error TS2339: Property 'method' does not exist on type 'Omit'. rest2.method; ~~~~~~ -!!! error TS2339: Property 'method' does not exist on type '{ normal: string; }'. +!!! error TS2339: Property 'method' does not exist on type '{ publicProp: string; }'. rest3.method; ~~~~~~ -!!! error TS2339: Property 'method' does not exist on type 'Omit'. +!!! error TS2339: Property 'method' does not exist on type 'Omit'. rest4.method; ~~~~~~ !!! error TS2339: Property 'method' does not exist on type '{}'. diff --git a/tests/baselines/reference/destructuringUnspreadableIntoRest.js b/tests/baselines/reference/destructuringUnspreadableIntoRest.js index 4d14cd72ddbbb..b1f092b065f2a 100644 --- a/tests/baselines/reference/destructuringUnspreadableIntoRest.js +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.js @@ -1,6 +1,9 @@ //// [destructuringUnspreadableIntoRest.ts] class A { - constructor(public normal: string) {} + constructor( + public publicProp: string, + private privateProp: string, + ) {} get getter(): number { return 1; @@ -9,10 +12,20 @@ class A { set setter(_v: number) {} method() { - const { ...rest1 } = this; - const { ...rest2 } = this as A; - const { normal: _1, ...rest3 } = this; - const { normal: _2, ...rest4 } = this as A; + 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.getter; rest2.getter; @@ -32,10 +45,20 @@ class A { } function destructure(x: T) { - const { ...rest1 } = x; - const { ...rest2 } = x as A; - const { normal: _1, ...rest3 } = x; - const { normal: _2, ...rest4 } = x as A; + 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.getter; rest2.getter; @@ -66,27 +89,28 @@ var __rest = (this && this.__rest) || function (s, e) { } return t; }; -var A = /** @class */ (function () { - function A(normal) { - this.normal = normal; +class A { + constructor(publicProp, privateProp) { + this.publicProp = publicProp; + this.privateProp = privateProp; } - Object.defineProperty(A.prototype, "getter", { - get: function () { - return 1; - }, - enumerable: false, - configurable: true - }); - 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, _1 = _a.normal, rest3 = __rest(_a, ["normal"]); - var _b = this, _2 = _b.normal, rest4 = __rest(_b, ["normal"]); + get getter() { + return 1; + } + set setter(_v) { } + method() { + const rest1 = __rest(this, []); + const rest2 = __rest(this, []); + const _a = this, { publicProp: _1 } = _a, rest3 = __rest(_a, ["publicProp"]); + const _b = this, { publicProp: _2 } = _b, rest4 = __rest(_b, ["publicProp"]); + rest1.publicProp; + rest2.publicProp; + rest3.publicProp; + rest4.publicProp; + rest1.privateProp; + rest2.privateProp; + rest3.privateProp; + rest4.privateProp; rest1.getter; rest2.getter; rest3.getter; @@ -99,14 +123,21 @@ var A = /** @class */ (function () { rest2.method; rest3.method; rest4.method; - }; - return A; -}()); + } +} function destructure(x) { - var rest1 = __rest(x, []); - var rest2 = __rest(x, []); - var _1 = x.normal, rest3 = __rest(x, ["normal"]); - var _a = x, _2 = _a.normal, rest4 = __rest(_a, ["normal"]); + const rest1 = __rest(x, []); + const rest2 = __rest(x, []); + const { publicProp: _1 } = x, rest3 = __rest(x, ["publicProp"]); + const _a = x, { publicProp: _2 } = _a, rest4 = __rest(_a, ["publicProp"]); + rest1.publicProp; + rest2.publicProp; + rest3.publicProp; + rest4.publicProp; + rest1.privateProp; + rest2.privateProp; + rest3.privateProp; + rest4.privateProp; rest1.getter; rest2.getter; rest3.getter; diff --git a/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols b/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols index 69321ce50b513..25224c3962a9c 100644 --- a/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols @@ -2,145 +2,207 @@ class A { >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) - constructor(public normal: string) {} ->normal : Symbol(A.normal, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) + constructor( + public publicProp: string, +>publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) + + private privateProp: string, +>privateProp : Symbol(A.privateProp, Decl(destructuringUnspreadableIntoRest.ts, 2, 34)) + + ) {} get getter(): number { ->getter : Symbol(A.getter, Decl(destructuringUnspreadableIntoRest.ts, 1, 41)) +>getter : Symbol(A.getter, Decl(destructuringUnspreadableIntoRest.ts, 4, 8)) return 1; } set setter(_v: number) {} ->setter : Symbol(A.setter, Decl(destructuringUnspreadableIntoRest.ts, 5, 5)) ->_v : Symbol(_v, Decl(destructuringUnspreadableIntoRest.ts, 7, 15)) +>setter : Symbol(A.setter, Decl(destructuringUnspreadableIntoRest.ts, 8, 5)) +>_v : Symbol(_v, Decl(destructuringUnspreadableIntoRest.ts, 10, 15)) method() { ->method : Symbol(A.method, Decl(destructuringUnspreadableIntoRest.ts, 7, 29)) +>method : Symbol(A.method, Decl(destructuringUnspreadableIntoRest.ts, 10, 29)) - const { ...rest1 } = this; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 10, 15)) + const { ...rest1 } = this; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 13, 15)) >this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) - const { ...rest2 } = this as A; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 11, 15)) + const { ...rest2 } = this as A; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) >this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) - const { normal: _1, ...rest3 } = this; ->normal : Symbol(A.normal, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->_1 : Symbol(_1, Decl(destructuringUnspreadableIntoRest.ts, 12, 15)) ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 12, 27)) + const { publicProp: _1, ...rest3 } = this; +>publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>_1 : Symbol(_1, Decl(destructuringUnspreadableIntoRest.ts, 15, 15)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 15, 31)) >this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) - const { normal: _2, ...rest4 } = this as A; ->normal : Symbol(A.normal, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->_2 : Symbol(_2, Decl(destructuringUnspreadableIntoRest.ts, 13, 15)) ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 13, 27)) + const { publicProp: _2, ...rest4 } = this as A; +>publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>_2 : Symbol(_2, Decl(destructuringUnspreadableIntoRest.ts, 16, 15)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) >this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) + rest1.publicProp; +>rest1.publicProp : Symbol(publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 13, 15)) +>publicProp : Symbol(publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) + + rest2.publicProp; +>rest2.publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) +>publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) + + rest3.publicProp; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 15, 31)) + + rest4.publicProp; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) + + rest1.privateProp; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 13, 15)) + + rest2.privateProp; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) + + rest3.privateProp; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 15, 31)) + + rest4.privateProp; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) + rest1.getter; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 10, 15)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 13, 15)) rest2.getter; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 11, 15)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) rest3.getter; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 12, 27)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 15, 31)) rest4.getter; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 13, 27)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) rest1.setter; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 10, 15)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 13, 15)) rest2.setter; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 11, 15)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) rest3.setter; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 12, 27)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 15, 31)) rest4.setter; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 13, 27)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) rest1.method; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 10, 15)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 13, 15)) rest2.method; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 11, 15)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) rest3.method; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 12, 27)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 15, 31)) rest4.method; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 13, 27)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) } } function destructure(x: T) { ->destructure : Symbol(destructure, Decl(destructuringUnspreadableIntoRest.ts, 30, 1)) ->T : Symbol(T, Decl(destructuringUnspreadableIntoRest.ts, 32, 21)) +>destructure : Symbol(destructure, Decl(destructuringUnspreadableIntoRest.ts, 43, 1)) +>T : Symbol(T, Decl(destructuringUnspreadableIntoRest.ts, 45, 21)) >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) ->x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 32, 34)) ->T : Symbol(T, Decl(destructuringUnspreadableIntoRest.ts, 32, 21)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 45, 34)) +>T : Symbol(T, Decl(destructuringUnspreadableIntoRest.ts, 45, 21)) - const { ...rest1 } = x; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 33, 11)) ->x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 32, 34)) + const { ...rest1 } = x; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 46, 11)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 45, 34)) - const { ...rest2 } = x as A; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 34, 11)) ->x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 32, 34)) + const { ...rest2 } = x as A; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 47, 11)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 45, 34)) >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) - const { normal: _1, ...rest3 } = x; ->normal : Symbol(A.normal, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->_1 : Symbol(_1, Decl(destructuringUnspreadableIntoRest.ts, 35, 11)) ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 35, 23)) ->x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 32, 34)) - - const { normal: _2, ...rest4 } = x as A; ->normal : Symbol(A.normal, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->_2 : Symbol(_2, Decl(destructuringUnspreadableIntoRest.ts, 36, 11)) ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 36, 23)) ->x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 32, 34)) + const { publicProp: _1, ...rest3 } = x; +>publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>_1 : Symbol(_1, Decl(destructuringUnspreadableIntoRest.ts, 48, 11)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 48, 27)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 45, 34)) + + const { publicProp: _2, ...rest4 } = x as A; +>publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>_2 : Symbol(_2, Decl(destructuringUnspreadableIntoRest.ts, 49, 11)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 49, 27)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 45, 34)) >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) + rest1.publicProp; +>rest1.publicProp : Symbol(publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 46, 11)) +>publicProp : Symbol(publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) + + rest2.publicProp; +>rest2.publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 47, 11)) +>publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) + + rest3.publicProp; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 48, 27)) + + rest4.publicProp; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 49, 27)) + + rest1.privateProp; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 46, 11)) + + rest2.privateProp; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 47, 11)) + + rest3.privateProp; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 48, 27)) + + rest4.privateProp; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 49, 27)) + rest1.getter; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 33, 11)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 46, 11)) rest2.getter; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 34, 11)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 47, 11)) rest3.getter; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 35, 23)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 48, 27)) rest4.getter; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 36, 23)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 49, 27)) rest1.setter; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 33, 11)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 46, 11)) rest2.setter; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 34, 11)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 47, 11)) rest3.setter; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 35, 23)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 48, 27)) rest4.setter; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 36, 23)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 49, 27)) rest1.method; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 33, 11)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 46, 11)) rest2.method; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 34, 11)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 47, 11)) rest3.method; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 35, 23)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 48, 27)) rest4.method; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 36, 23)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 49, 27)) } diff --git a/tests/baselines/reference/destructuringUnspreadableIntoRest.types b/tests/baselines/reference/destructuringUnspreadableIntoRest.types index d98edbac75620..2a7fb760052e1 100644 --- a/tests/baselines/reference/destructuringUnspreadableIntoRest.types +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.types @@ -2,8 +2,14 @@ class A { >A : A - constructor(public normal: string) {} ->normal : string + constructor( + public publicProp: string, +>publicProp : string + + private privateProp: string, +>privateProp : string + + ) {} get getter(): number { >getter : number @@ -19,28 +25,68 @@ class A { method() { >method : () => void - const { ...rest1 } = this; + const { ...rest1 } = this; >rest1 : Omit >this : this - const { ...rest2 } = this as A; ->rest2 : { normal: string; } + const { ...rest2 } = this as A; +>rest2 : { publicProp: string; } >this as A : A >this : this - const { normal: _1, ...rest3 } = this; ->normal : any + const { publicProp: _1, ...rest3 } = this; +>publicProp : any >_1 : string ->rest3 : Omit +>rest3 : Omit >this : this - const { normal: _2, ...rest4 } = this as A; ->normal : any + const { publicProp: _2, ...rest4 } = this as A; +>publicProp : any >_2 : string >rest4 : {} >this as A : A >this : this + rest1.publicProp; +>rest1.publicProp : this["publicProp"] +>rest1 : Omit +>publicProp : this["publicProp"] + + rest2.publicProp; +>rest2.publicProp : string +>rest2 : { publicProp: string; } +>publicProp : string + + rest3.publicProp; +>rest3.publicProp : any +>rest3 : Omit +>publicProp : any + + rest4.publicProp; +>rest4.publicProp : any +>rest4 : {} +>publicProp : any + + rest1.privateProp; +>rest1.privateProp : any +>rest1 : Omit +>privateProp : any + + rest2.privateProp; +>rest2.privateProp : any +>rest2 : { publicProp: string; } +>privateProp : any + + rest3.privateProp; +>rest3.privateProp : any +>rest3 : Omit +>privateProp : any + + rest4.privateProp; +>rest4.privateProp : any +>rest4 : {} +>privateProp : any + rest1.getter; >rest1.getter : any >rest1 : Omit @@ -48,12 +94,12 @@ class A { rest2.getter; >rest2.getter : any ->rest2 : { normal: string; } +>rest2 : { publicProp: string; } >getter : any rest3.getter; >rest3.getter : any ->rest3 : Omit +>rest3 : Omit >getter : any rest4.getter; @@ -68,12 +114,12 @@ class A { rest2.setter; >rest2.setter : any ->rest2 : { normal: string; } +>rest2 : { publicProp: string; } >setter : any rest3.setter; >rest3.setter : any ->rest3 : Omit +>rest3 : Omit >setter : any rest4.setter; @@ -88,12 +134,12 @@ class A { rest2.method; >rest2.method : any ->rest2 : { normal: string; } +>rest2 : { publicProp: string; } >method : any rest3.method; >rest3.method : any ->rest3 : Omit +>rest3 : Omit >method : any rest4.method; @@ -107,28 +153,68 @@ function destructure(x: T) { >destructure : (x: T) => void >x : T - const { ...rest1 } = x; + const { ...rest1 } = x; >rest1 : Omit >x : T - const { ...rest2 } = x as A; ->rest2 : { normal: string; } + const { ...rest2 } = x as A; +>rest2 : { publicProp: string; } >x as A : A >x : T - const { normal: _1, ...rest3 } = x; ->normal : any + const { publicProp: _1, ...rest3 } = x; +>publicProp : any >_1 : string ->rest3 : Omit +>rest3 : Omit >x : T - const { normal: _2, ...rest4 } = x as A; ->normal : any + const { publicProp: _2, ...rest4 } = x as A; +>publicProp : any >_2 : string >rest4 : {} >x as A : A >x : T + rest1.publicProp; +>rest1.publicProp : T["publicProp"] +>rest1 : Omit +>publicProp : T["publicProp"] + + rest2.publicProp; +>rest2.publicProp : string +>rest2 : { publicProp: string; } +>publicProp : string + + rest3.publicProp; +>rest3.publicProp : any +>rest3 : Omit +>publicProp : any + + rest4.publicProp; +>rest4.publicProp : any +>rest4 : {} +>publicProp : any + + rest1.privateProp; +>rest1.privateProp : any +>rest1 : Omit +>privateProp : any + + rest2.privateProp; +>rest2.privateProp : any +>rest2 : { publicProp: string; } +>privateProp : any + + rest3.privateProp; +>rest3.privateProp : any +>rest3 : Omit +>privateProp : any + + rest4.privateProp; +>rest4.privateProp : any +>rest4 : {} +>privateProp : any + rest1.getter; >rest1.getter : any >rest1 : Omit @@ -136,12 +222,12 @@ function destructure(x: T) { rest2.getter; >rest2.getter : any ->rest2 : { normal: string; } +>rest2 : { publicProp: string; } >getter : any rest3.getter; >rest3.getter : any ->rest3 : Omit +>rest3 : Omit >getter : any rest4.getter; @@ -156,12 +242,12 @@ function destructure(x: T) { rest2.setter; >rest2.setter : any ->rest2 : { normal: string; } +>rest2 : { publicProp: string; } >setter : any rest3.setter; >rest3.setter : any ->rest3 : Omit +>rest3 : Omit >setter : any rest4.setter; @@ -176,12 +262,12 @@ function destructure(x: T) { rest2.method; >rest2.method : any ->rest2 : { normal: string; } +>rest2 : { publicProp: string; } >method : any rest3.method; >rest3.method : any ->rest3 : Omit +>rest3 : Omit >method : any rest4.method; diff --git a/tests/cases/compiler/destructuringUnspreadableIntoRest.ts b/tests/cases/compiler/destructuringUnspreadableIntoRest.ts index 27ad0a0085b94..e85388da9c667 100644 --- a/tests/cases/compiler/destructuringUnspreadableIntoRest.ts +++ b/tests/cases/compiler/destructuringUnspreadableIntoRest.ts @@ -1,5 +1,9 @@ +//@target: ES6 class A { - constructor(public normal: string) {} + constructor( + public publicProp: string, + private privateProp: string, + ) {} get getter(): number { return 1; @@ -8,10 +12,20 @@ class A { set setter(_v: number) {} method() { - const { ...rest1 } = this; - const { ...rest2 } = this as A; - const { normal: _1, ...rest3 } = this; - const { normal: _2, ...rest4 } = this as A; + 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.getter; rest2.getter; @@ -31,10 +45,20 @@ class A { } function destructure(x: T) { - const { ...rest1 } = x; - const { ...rest2 } = x as A; - const { normal: _1, ...rest3 } = x; - const { normal: _2, ...rest4 } = x as A; + 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.getter; rest2.getter; From c6f0f2f8edf1c4b485dcb85a54feeac1ac72b8fb Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 9 Dec 2021 11:12:40 -0800 Subject: [PATCH 9/9] Also test protected, given omitting private/protected is correct --- ...structuringUnspreadableIntoRest.errors.txt | 109 +++++++----- .../destructuringUnspreadableIntoRest.js | 22 ++- .../destructuringUnspreadableIntoRest.symbols | 155 ++++++++++-------- .../destructuringUnspreadableIntoRest.types | 43 +++++ .../destructuringUnspreadableIntoRest.ts | 11 ++ 5 files changed, 238 insertions(+), 102 deletions(-) diff --git a/tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt b/tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt index 57c534c24017c..20bcc06382504 100644 --- a/tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt @@ -1,46 +1,55 @@ -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(21,15): error TS2339: Property 'publicProp' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(22,15): error TS2339: Property 'publicProp' does not exist on type '{}'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(24,15): error TS2339: Property 'privateProp' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(25,15): error TS2339: Property 'privateProp' does not exist on type '{ publicProp: string; }'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(26,15): error TS2339: Property 'privateProp' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(27,15): error TS2339: Property 'privateProp' does not exist on type '{}'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(29,15): error TS2339: Property 'getter' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(30,15): error TS2339: Property 'getter' does not exist on type '{ publicProp: string; }'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(31,15): error TS2339: Property 'getter' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(32,15): error TS2339: Property 'getter' does not exist on type '{}'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(34,15): error TS2339: Property 'setter' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(35,15): error TS2339: Property 'setter' does not exist on type '{ publicProp: string; }'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(36,15): error TS2339: Property 'setter' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(37,15): error TS2339: Property 'setter' does not exist on type '{}'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(39,15): error TS2339: Property 'method' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(40,15): error TS2339: Property 'method' does not exist on type '{ publicProp: string; }'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(41,15): error TS2339: Property 'method' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(42,15): error TS2339: Property 'method' does not exist on type '{}'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(54,11): error TS2339: Property 'publicProp' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(55,11): error TS2339: Property 'publicProp' does not exist on type '{}'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(57,11): error TS2339: Property 'privateProp' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(58,11): error TS2339: Property 'privateProp' does not exist on type '{ publicProp: string; }'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(59,11): error TS2339: Property 'privateProp' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(60,11): error TS2339: Property 'privateProp' does not exist on type '{}'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(62,11): error TS2339: Property 'getter' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(63,11): error TS2339: Property 'getter' does not exist on type '{ publicProp: string; }'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(64,11): error TS2339: Property 'getter' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(65,11): error TS2339: Property 'getter' does not exist on type '{}'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(67,11): error TS2339: Property 'setter' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(68,11): error TS2339: Property 'setter' does not exist on type '{ publicProp: string; }'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(69,11): error TS2339: Property 'setter' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(70,11): error TS2339: Property 'setter' does not exist on type '{}'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(72,11): error TS2339: Property 'method' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(73,11): error TS2339: Property 'method' does not exist on type '{ publicProp: string; }'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(74,11): error TS2339: Property 'method' does not exist on type 'Omit'. -tests/cases/compiler/destructuringUnspreadableIntoRest.ts(75,11): error TS2339: Property 'method' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(22,15): error TS2339: Property 'publicProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(23,15): error TS2339: Property 'publicProp' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(25,15): error TS2339: Property 'privateProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(26,15): error TS2339: Property 'privateProp' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(27,15): error TS2339: Property 'privateProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(28,15): error TS2339: Property 'privateProp' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(30,15): error TS2339: Property 'protectedProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(31,15): error TS2339: Property 'protectedProp' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(32,15): error TS2339: Property 'protectedProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(33,15): error TS2339: Property 'protectedProp' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(35,15): error TS2339: Property 'getter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(36,15): error TS2339: Property 'getter' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(37,15): error TS2339: Property 'getter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(38,15): error TS2339: Property 'getter' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(40,15): error TS2339: Property 'setter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(41,15): error TS2339: Property 'setter' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(42,15): error TS2339: Property 'setter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(43,15): error TS2339: Property 'setter' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(45,15): error TS2339: Property 'method' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(46,15): error TS2339: Property 'method' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(47,15): error TS2339: Property 'method' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(48,15): error TS2339: Property 'method' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(60,11): error TS2339: Property 'publicProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(61,11): error TS2339: Property 'publicProp' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(63,11): error TS2339: Property 'privateProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(64,11): error TS2339: Property 'privateProp' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(65,11): error TS2339: Property 'privateProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(66,11): error TS2339: Property 'privateProp' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(68,11): error TS2339: Property 'protectedProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(69,11): error TS2339: Property 'protectedProp' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(70,11): error TS2339: Property 'protectedProp' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(71,11): error TS2339: Property 'protectedProp' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(73,11): error TS2339: Property 'getter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(74,11): error TS2339: Property 'getter' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(75,11): error TS2339: Property 'getter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(76,11): error TS2339: Property 'getter' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(78,11): error TS2339: Property 'setter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(79,11): error TS2339: Property 'setter' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(80,11): error TS2339: Property 'setter' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(81,11): error TS2339: Property 'setter' does not exist on type '{}'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(83,11): error TS2339: Property 'method' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(84,11): error TS2339: Property 'method' does not exist on type '{ publicProp: string; }'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(85,11): error TS2339: Property 'method' does not exist on type 'Omit'. +tests/cases/compiler/destructuringUnspreadableIntoRest.ts(86,11): error TS2339: Property 'method' does not exist on type '{}'. -==== tests/cases/compiler/destructuringUnspreadableIntoRest.ts (36 errors) ==== +==== tests/cases/compiler/destructuringUnspreadableIntoRest.ts (44 errors) ==== class A { constructor( public publicProp: string, private privateProp: string, + protected protectedProp: string, ) {} get getter(): number { @@ -77,6 +86,19 @@ tests/cases/compiler/destructuringUnspreadableIntoRest.ts(75,11): error TS2339: ~~~~~~~~~~~ !!! error TS2339: Property 'privateProp' does not exist on type '{}'. + rest1.protectedProp; + ~~~~~~~~~~~~~ +!!! error TS2339: Property 'protectedProp' does not exist on type 'Omit'. + rest2.protectedProp; + ~~~~~~~~~~~~~ +!!! error TS2339: Property 'protectedProp' does not exist on type '{ publicProp: string; }'. + rest3.protectedProp; + ~~~~~~~~~~~~~ +!!! error TS2339: Property 'protectedProp' does not exist on type 'Omit'. + rest4.protectedProp; + ~~~~~~~~~~~~~ +!!! error TS2339: Property 'protectedProp' does not exist on type '{}'. + rest1.getter; ~~~~~~ !!! error TS2339: Property 'getter' does not exist on type 'Omit'. @@ -146,6 +168,19 @@ tests/cases/compiler/destructuringUnspreadableIntoRest.ts(75,11): error TS2339: ~~~~~~~~~~~ !!! error TS2339: Property 'privateProp' does not exist on type '{}'. + rest1.protectedProp; + ~~~~~~~~~~~~~ +!!! error TS2339: Property 'protectedProp' does not exist on type 'Omit'. + rest2.protectedProp; + ~~~~~~~~~~~~~ +!!! error TS2339: Property 'protectedProp' does not exist on type '{ publicProp: string; }'. + rest3.protectedProp; + ~~~~~~~~~~~~~ +!!! error TS2339: Property 'protectedProp' does not exist on type 'Omit'. + rest4.protectedProp; + ~~~~~~~~~~~~~ +!!! error TS2339: Property 'protectedProp' does not exist on type '{}'. + rest1.getter; ~~~~~~ !!! error TS2339: Property 'getter' does not exist on type 'Omit'. diff --git a/tests/baselines/reference/destructuringUnspreadableIntoRest.js b/tests/baselines/reference/destructuringUnspreadableIntoRest.js index b1f092b065f2a..e4ee1a835cec4 100644 --- a/tests/baselines/reference/destructuringUnspreadableIntoRest.js +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.js @@ -3,6 +3,7 @@ class A { constructor( public publicProp: string, private privateProp: string, + protected protectedProp: string, ) {} get getter(): number { @@ -27,6 +28,11 @@ class A { rest3.privateProp; rest4.privateProp; + rest1.protectedProp; + rest2.protectedProp; + rest3.protectedProp; + rest4.protectedProp; + rest1.getter; rest2.getter; rest3.getter; @@ -60,6 +66,11 @@ function destructure(x: T) { rest3.privateProp; rest4.privateProp; + rest1.protectedProp; + rest2.protectedProp; + rest3.protectedProp; + rest4.protectedProp; + rest1.getter; rest2.getter; rest3.getter; @@ -90,9 +101,10 @@ var __rest = (this && this.__rest) || function (s, e) { return t; }; class A { - constructor(publicProp, privateProp) { + constructor(publicProp, privateProp, protectedProp) { this.publicProp = publicProp; this.privateProp = privateProp; + this.protectedProp = protectedProp; } get getter() { return 1; @@ -111,6 +123,10 @@ class A { rest2.privateProp; rest3.privateProp; rest4.privateProp; + rest1.protectedProp; + rest2.protectedProp; + rest3.protectedProp; + rest4.protectedProp; rest1.getter; rest2.getter; rest3.getter; @@ -138,6 +154,10 @@ function destructure(x) { rest2.privateProp; rest3.privateProp; rest4.privateProp; + rest1.protectedProp; + rest2.protectedProp; + rest3.protectedProp; + rest4.protectedProp; rest1.getter; rest2.getter; rest3.getter; diff --git a/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols b/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols index 25224c3962a9c..557afeeffa912 100644 --- a/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols @@ -9,200 +9,227 @@ class A { private privateProp: string, >privateProp : Symbol(A.privateProp, Decl(destructuringUnspreadableIntoRest.ts, 2, 34)) + protected protectedProp: string, +>protectedProp : Symbol(A.protectedProp, Decl(destructuringUnspreadableIntoRest.ts, 3, 36)) + ) {} get getter(): number { ->getter : Symbol(A.getter, Decl(destructuringUnspreadableIntoRest.ts, 4, 8)) +>getter : Symbol(A.getter, Decl(destructuringUnspreadableIntoRest.ts, 5, 8)) return 1; } set setter(_v: number) {} ->setter : Symbol(A.setter, Decl(destructuringUnspreadableIntoRest.ts, 8, 5)) ->_v : Symbol(_v, Decl(destructuringUnspreadableIntoRest.ts, 10, 15)) +>setter : Symbol(A.setter, Decl(destructuringUnspreadableIntoRest.ts, 9, 5)) +>_v : Symbol(_v, Decl(destructuringUnspreadableIntoRest.ts, 11, 15)) method() { ->method : Symbol(A.method, Decl(destructuringUnspreadableIntoRest.ts, 10, 29)) +>method : Symbol(A.method, Decl(destructuringUnspreadableIntoRest.ts, 11, 29)) const { ...rest1 } = this; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 13, 15)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) >this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) const { ...rest2 } = this as A; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 15, 15)) >this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) const { publicProp: _1, ...rest3 } = this; >publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->_1 : Symbol(_1, Decl(destructuringUnspreadableIntoRest.ts, 15, 15)) ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 15, 31)) +>_1 : Symbol(_1, Decl(destructuringUnspreadableIntoRest.ts, 16, 15)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) >this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) const { publicProp: _2, ...rest4 } = this as A; >publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->_2 : Symbol(_2, Decl(destructuringUnspreadableIntoRest.ts, 16, 15)) ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) +>_2 : Symbol(_2, Decl(destructuringUnspreadableIntoRest.ts, 17, 15)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 17, 31)) >this : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) rest1.publicProp; >rest1.publicProp : Symbol(publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 13, 15)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) >publicProp : Symbol(publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) rest2.publicProp; >rest2.publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 15, 15)) >publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) rest3.publicProp; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 15, 31)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) rest4.publicProp; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 17, 31)) rest1.privateProp; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 13, 15)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) rest2.privateProp; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 15, 15)) rest3.privateProp; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 15, 31)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) rest4.privateProp; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 17, 31)) + + rest1.protectedProp; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) + + rest2.protectedProp; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 15, 15)) + + rest3.protectedProp; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) + + rest4.protectedProp; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 17, 31)) rest1.getter; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 13, 15)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) rest2.getter; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 15, 15)) rest3.getter; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 15, 31)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) rest4.getter; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 17, 31)) rest1.setter; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 13, 15)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) rest2.setter; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 15, 15)) rest3.setter; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 15, 31)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) rest4.setter; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 17, 31)) rest1.method; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 13, 15)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) rest2.method; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 15, 15)) rest3.method; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 15, 31)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) rest4.method; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 16, 31)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 17, 31)) } } function destructure(x: T) { ->destructure : Symbol(destructure, Decl(destructuringUnspreadableIntoRest.ts, 43, 1)) ->T : Symbol(T, Decl(destructuringUnspreadableIntoRest.ts, 45, 21)) +>destructure : Symbol(destructure, Decl(destructuringUnspreadableIntoRest.ts, 49, 1)) +>T : Symbol(T, Decl(destructuringUnspreadableIntoRest.ts, 51, 21)) >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) ->x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 45, 34)) ->T : Symbol(T, Decl(destructuringUnspreadableIntoRest.ts, 45, 21)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 51, 34)) +>T : Symbol(T, Decl(destructuringUnspreadableIntoRest.ts, 51, 21)) const { ...rest1 } = x; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 46, 11)) ->x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 45, 34)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 52, 11)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 51, 34)) const { ...rest2 } = x as A; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 47, 11)) ->x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 45, 34)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 53, 11)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 51, 34)) >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) const { publicProp: _1, ...rest3 } = x; >publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->_1 : Symbol(_1, Decl(destructuringUnspreadableIntoRest.ts, 48, 11)) ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 48, 27)) ->x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 45, 34)) +>_1 : Symbol(_1, Decl(destructuringUnspreadableIntoRest.ts, 54, 11)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 54, 27)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 51, 34)) const { publicProp: _2, ...rest4 } = x as A; >publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->_2 : Symbol(_2, Decl(destructuringUnspreadableIntoRest.ts, 49, 11)) ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 49, 27)) ->x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 45, 34)) +>_2 : Symbol(_2, Decl(destructuringUnspreadableIntoRest.ts, 55, 11)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 55, 27)) +>x : Symbol(x, Decl(destructuringUnspreadableIntoRest.ts, 51, 34)) >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) rest1.publicProp; >rest1.publicProp : Symbol(publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 46, 11)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 52, 11)) >publicProp : Symbol(publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) rest2.publicProp; >rest2.publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 47, 11)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 53, 11)) >publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) rest3.publicProp; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 48, 27)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 54, 27)) rest4.publicProp; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 49, 27)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 55, 27)) rest1.privateProp; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 46, 11)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 52, 11)) rest2.privateProp; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 47, 11)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 53, 11)) rest3.privateProp; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 48, 27)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 54, 27)) rest4.privateProp; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 49, 27)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 55, 27)) + + rest1.protectedProp; +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 52, 11)) + + rest2.protectedProp; +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 53, 11)) + + rest3.protectedProp; +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 54, 27)) + + rest4.protectedProp; +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 55, 27)) rest1.getter; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 46, 11)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 52, 11)) rest2.getter; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 47, 11)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 53, 11)) rest3.getter; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 48, 27)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 54, 27)) rest4.getter; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 49, 27)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 55, 27)) rest1.setter; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 46, 11)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 52, 11)) rest2.setter; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 47, 11)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 53, 11)) rest3.setter; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 48, 27)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 54, 27)) rest4.setter; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 49, 27)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 55, 27)) rest1.method; ->rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 46, 11)) +>rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 52, 11)) rest2.method; ->rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 47, 11)) +>rest2 : Symbol(rest2, Decl(destructuringUnspreadableIntoRest.ts, 53, 11)) rest3.method; ->rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 48, 27)) +>rest3 : Symbol(rest3, Decl(destructuringUnspreadableIntoRest.ts, 54, 27)) rest4.method; ->rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 49, 27)) +>rest4 : Symbol(rest4, Decl(destructuringUnspreadableIntoRest.ts, 55, 27)) } diff --git a/tests/baselines/reference/destructuringUnspreadableIntoRest.types b/tests/baselines/reference/destructuringUnspreadableIntoRest.types index 2a7fb760052e1..5fefa899662b3 100644 --- a/tests/baselines/reference/destructuringUnspreadableIntoRest.types +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.types @@ -9,6 +9,9 @@ class A { private privateProp: string, >privateProp : string + protected protectedProp: string, +>protectedProp : string + ) {} get getter(): number { @@ -87,6 +90,26 @@ class A { >rest4 : {} >privateProp : any + rest1.protectedProp; +>rest1.protectedProp : any +>rest1 : Omit +>protectedProp : any + + rest2.protectedProp; +>rest2.protectedProp : any +>rest2 : { publicProp: string; } +>protectedProp : any + + rest3.protectedProp; +>rest3.protectedProp : any +>rest3 : Omit +>protectedProp : any + + rest4.protectedProp; +>rest4.protectedProp : any +>rest4 : {} +>protectedProp : any + rest1.getter; >rest1.getter : any >rest1 : Omit @@ -215,6 +238,26 @@ function destructure(x: T) { >rest4 : {} >privateProp : any + rest1.protectedProp; +>rest1.protectedProp : any +>rest1 : Omit +>protectedProp : any + + rest2.protectedProp; +>rest2.protectedProp : any +>rest2 : { publicProp: string; } +>protectedProp : any + + rest3.protectedProp; +>rest3.protectedProp : any +>rest3 : Omit +>protectedProp : any + + rest4.protectedProp; +>rest4.protectedProp : any +>rest4 : {} +>protectedProp : any + rest1.getter; >rest1.getter : any >rest1 : Omit diff --git a/tests/cases/compiler/destructuringUnspreadableIntoRest.ts b/tests/cases/compiler/destructuringUnspreadableIntoRest.ts index e85388da9c667..11e0cc73dea4b 100644 --- a/tests/cases/compiler/destructuringUnspreadableIntoRest.ts +++ b/tests/cases/compiler/destructuringUnspreadableIntoRest.ts @@ -3,6 +3,7 @@ class A { constructor( public publicProp: string, private privateProp: string, + protected protectedProp: string, ) {} get getter(): number { @@ -27,6 +28,11 @@ class A { rest3.privateProp; rest4.privateProp; + rest1.protectedProp; + rest2.protectedProp; + rest3.protectedProp; + rest4.protectedProp; + rest1.getter; rest2.getter; rest3.getter; @@ -60,6 +66,11 @@ function destructure(x: T) { rest3.privateProp; rest4.privateProp; + rest1.protectedProp; + rest2.protectedProp; + rest3.protectedProp; + rest4.protectedProp; + rest1.getter; rest2.getter; rest3.getter;