forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explicitly Omit unspreadable properties from rest type in the generic…
… case (microsoft#47078)
- Loading branch information
1 parent
87d083f
commit 426f643
Showing
6 changed files
with
1,067 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
223 changes: 223 additions & 0 deletions
223
tests/baselines/reference/destructuringUnspreadableIntoRest.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(22,15): error TS2339: Property 'publicProp' does not exist on type 'Omit<this, "publicProp" | "getter" | "setter" | "method">'. | ||
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<this, "getter" | "setter" | "method">'. | ||
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<this, "publicProp" | "getter" | "setter" | "method">'. | ||
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<this, "getter" | "setter" | "method">'. | ||
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<this, "publicProp" | "getter" | "setter" | "method">'. | ||
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<this, "getter" | "setter" | "method">'. | ||
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<this, "publicProp" | "getter" | "setter" | "method">'. | ||
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<this, "getter" | "setter" | "method">'. | ||
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<this, "publicProp" | "getter" | "setter" | "method">'. | ||
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<this, "getter" | "setter" | "method">'. | ||
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<this, "publicProp" | "getter" | "setter" | "method">'. | ||
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<T, "publicProp" | "getter" | "setter" | "method">'. | ||
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<T, "getter" | "setter" | "method">'. | ||
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<T, "publicProp" | "getter" | "setter" | "method">'. | ||
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<T, "getter" | "setter" | "method">'. | ||
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<T, "publicProp" | "getter" | "setter" | "method">'. | ||
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<T, "getter" | "setter" | "method">'. | ||
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<T, "publicProp" | "getter" | "setter" | "method">'. | ||
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<T, "getter" | "setter" | "method">'. | ||
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<T, "publicProp" | "getter" | "setter" | "method">'. | ||
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<T, "getter" | "setter" | "method">'. | ||
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<T, "publicProp" | "getter" | "setter" | "method">'. | ||
tests/cases/compiler/destructuringUnspreadableIntoRest.ts(86,11): error TS2339: Property 'method' does not exist on type '{}'. | ||
|
||
|
||
==== tests/cases/compiler/destructuringUnspreadableIntoRest.ts (44 errors) ==== | ||
class A { | ||
constructor( | ||
public publicProp: string, | ||
private privateProp: string, | ||
protected protectedProp: string, | ||
) {} | ||
|
||
get getter(): number { | ||
return 1; | ||
} | ||
|
||
set setter(_v: number) {} | ||
|
||
method() { | ||
const { ...rest1 } = this; | ||
const { ...rest2 } = this as A; | ||
const { publicProp: _1, ...rest3 } = this; | ||
const { publicProp: _2, ...rest4 } = this as A; | ||
|
||
rest1.publicProp; | ||
rest2.publicProp; | ||
rest3.publicProp; | ||
~~~~~~~~~~ | ||
!!! error TS2339: Property 'publicProp' does not exist on type 'Omit<this, "publicProp" | "getter" | "setter" | "method">'. | ||
rest4.publicProp; | ||
~~~~~~~~~~ | ||
!!! error TS2339: Property 'publicProp' does not exist on type '{}'. | ||
|
||
rest1.privateProp; | ||
~~~~~~~~~~~ | ||
!!! error TS2339: Property 'privateProp' does not exist on type 'Omit<this, "getter" | "setter" | "method">'. | ||
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<this, "publicProp" | "getter" | "setter" | "method">'. | ||
rest4.privateProp; | ||
~~~~~~~~~~~ | ||
!!! error TS2339: Property 'privateProp' does not exist on type '{}'. | ||
|
||
rest1.protectedProp; | ||
~~~~~~~~~~~~~ | ||
!!! error TS2339: Property 'protectedProp' does not exist on type 'Omit<this, "getter" | "setter" | "method">'. | ||
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<this, "publicProp" | "getter" | "setter" | "method">'. | ||
rest4.protectedProp; | ||
~~~~~~~~~~~~~ | ||
!!! error TS2339: Property 'protectedProp' does not exist on type '{}'. | ||
|
||
rest1.getter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'getter' does not exist on type 'Omit<this, "getter" | "setter" | "method">'. | ||
rest2.getter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'getter' does not exist on type '{ publicProp: string; }'. | ||
rest3.getter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'getter' does not exist on type 'Omit<this, "publicProp" | "getter" | "setter" | "method">'. | ||
rest4.getter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'getter' does not exist on type '{}'. | ||
|
||
rest1.setter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'setter' does not exist on type 'Omit<this, "getter" | "setter" | "method">'. | ||
rest2.setter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'setter' does not exist on type '{ publicProp: string; }'. | ||
rest3.setter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'setter' does not exist on type 'Omit<this, "publicProp" | "getter" | "setter" | "method">'. | ||
rest4.setter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'setter' does not exist on type '{}'. | ||
|
||
rest1.method; | ||
~~~~~~ | ||
!!! error TS2339: Property 'method' does not exist on type 'Omit<this, "getter" | "setter" | "method">'. | ||
rest2.method; | ||
~~~~~~ | ||
!!! error TS2339: Property 'method' does not exist on type '{ publicProp: string; }'. | ||
rest3.method; | ||
~~~~~~ | ||
!!! error TS2339: Property 'method' does not exist on type 'Omit<this, "publicProp" | "getter" | "setter" | "method">'. | ||
rest4.method; | ||
~~~~~~ | ||
!!! error TS2339: Property 'method' does not exist on type '{}'. | ||
} | ||
} | ||
|
||
function destructure<T extends A>(x: T) { | ||
const { ...rest1 } = x; | ||
const { ...rest2 } = x as A; | ||
const { 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<T, "publicProp" | "getter" | "setter" | "method">'. | ||
rest4.publicProp; | ||
~~~~~~~~~~ | ||
!!! error TS2339: Property 'publicProp' does not exist on type '{}'. | ||
|
||
rest1.privateProp; | ||
~~~~~~~~~~~ | ||
!!! error TS2339: Property 'privateProp' does not exist on type 'Omit<T, "getter" | "setter" | "method">'. | ||
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<T, "publicProp" | "getter" | "setter" | "method">'. | ||
rest4.privateProp; | ||
~~~~~~~~~~~ | ||
!!! error TS2339: Property 'privateProp' does not exist on type '{}'. | ||
|
||
rest1.protectedProp; | ||
~~~~~~~~~~~~~ | ||
!!! error TS2339: Property 'protectedProp' does not exist on type 'Omit<T, "getter" | "setter" | "method">'. | ||
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<T, "publicProp" | "getter" | "setter" | "method">'. | ||
rest4.protectedProp; | ||
~~~~~~~~~~~~~ | ||
!!! error TS2339: Property 'protectedProp' does not exist on type '{}'. | ||
|
||
rest1.getter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'getter' does not exist on type 'Omit<T, "getter" | "setter" | "method">'. | ||
rest2.getter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'getter' does not exist on type '{ publicProp: string; }'. | ||
rest3.getter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'getter' does not exist on type 'Omit<T, "publicProp" | "getter" | "setter" | "method">'. | ||
rest4.getter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'getter' does not exist on type '{}'. | ||
|
||
rest1.setter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'setter' does not exist on type 'Omit<T, "getter" | "setter" | "method">'. | ||
rest2.setter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'setter' does not exist on type '{ publicProp: string; }'. | ||
rest3.setter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'setter' does not exist on type 'Omit<T, "publicProp" | "getter" | "setter" | "method">'. | ||
rest4.setter; | ||
~~~~~~ | ||
!!! error TS2339: Property 'setter' does not exist on type '{}'. | ||
|
||
rest1.method; | ||
~~~~~~ | ||
!!! error TS2339: Property 'method' does not exist on type 'Omit<T, "getter" | "setter" | "method">'. | ||
rest2.method; | ||
~~~~~~ | ||
!!! error TS2339: Property 'method' does not exist on type '{ publicProp: string; }'. | ||
rest3.method; | ||
~~~~~~ | ||
!!! error TS2339: Property 'method' does not exist on type 'Omit<T, "publicProp" | "getter" | "setter" | "method">'. | ||
rest4.method; | ||
~~~~~~ | ||
!!! error TS2339: Property 'method' does not exist on type '{}'. | ||
} | ||
|
Oops, something went wrong.