From 60e7b5d17e9fc7ebfc7c55154cc000db0d773721 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 24 Apr 2019 16:43:17 -0700 Subject: [PATCH 1/4] Added tests. --- tests/cases/compiler/omitTypeTestErrors01.ts | 19 +++++++++++++++++++ tests/cases/compiler/omitTypeTests01.ts | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/cases/compiler/omitTypeTestErrors01.ts create mode 100644 tests/cases/compiler/omitTypeTests01.ts diff --git a/tests/cases/compiler/omitTypeTestErrors01.ts b/tests/cases/compiler/omitTypeTestErrors01.ts new file mode 100644 index 0000000000000..fd3f5fc1e5d2a --- /dev/null +++ b/tests/cases/compiler/omitTypeTestErrors01.ts @@ -0,0 +1,19 @@ +// @declaration: true + +interface Foo { + a: string; + b: number; + c: boolean; +} + +export type Bar = Omit; +export type Baz = Omit; + +export function getBarC(bar: Bar) { + return bar.c; +} + +export function getBazB(baz: Baz) { + return baz.b; +} + diff --git a/tests/cases/compiler/omitTypeTests01.ts b/tests/cases/compiler/omitTypeTests01.ts new file mode 100644 index 0000000000000..d3b2ce26e1ec4 --- /dev/null +++ b/tests/cases/compiler/omitTypeTests01.ts @@ -0,0 +1,19 @@ +// @declaration: true + +interface Foo { + a: string; + b: number; + c: boolean; +} + +export type Bar = Omit; +export type Baz = Omit; + +export function getBarA(bar: Bar) { + return bar.a; +} + +export function getBazA(baz: Baz) { + return baz.a; +} + From 622cb421373e47cac3672795b64748723734570f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 24 Apr 2019 16:45:30 -0700 Subject: [PATCH 2/4] Accepted baselines. --- .../reference/omitTypeTestErrors01.errors.txt | 27 +++++++++++ .../reference/omitTypeTestErrors01.js | 44 +++++++++++++++++ .../reference/omitTypeTestErrors01.symbols | 43 +++++++++++++++++ .../reference/omitTypeTestErrors01.types | 39 +++++++++++++++ tests/baselines/reference/omitTypeTests01.js | 44 +++++++++++++++++ .../reference/omitTypeTests01.symbols | 47 +++++++++++++++++++ .../baselines/reference/omitTypeTests01.types | 39 +++++++++++++++ 7 files changed, 283 insertions(+) create mode 100644 tests/baselines/reference/omitTypeTestErrors01.errors.txt create mode 100644 tests/baselines/reference/omitTypeTestErrors01.js create mode 100644 tests/baselines/reference/omitTypeTestErrors01.symbols create mode 100644 tests/baselines/reference/omitTypeTestErrors01.types create mode 100644 tests/baselines/reference/omitTypeTests01.js create mode 100644 tests/baselines/reference/omitTypeTests01.symbols create mode 100644 tests/baselines/reference/omitTypeTests01.types diff --git a/tests/baselines/reference/omitTypeTestErrors01.errors.txt b/tests/baselines/reference/omitTypeTestErrors01.errors.txt new file mode 100644 index 0000000000000..a66ab384b8935 --- /dev/null +++ b/tests/baselines/reference/omitTypeTestErrors01.errors.txt @@ -0,0 +1,27 @@ +tests/cases/compiler/omitTypeTestErrors01.ts(11,16): error TS2339: Property 'c' does not exist on type 'Pick'. +tests/cases/compiler/omitTypeTestErrors01.ts(15,16): error TS2339: Property 'b' does not exist on type 'Pick'. + + +==== tests/cases/compiler/omitTypeTestErrors01.ts (2 errors) ==== + interface Foo { + a: string; + b: number; + c: boolean; + } + + export type Bar = Omit; + export type Baz = Omit; + + export function getBarC(bar: Bar) { + return bar.c; + ~ +!!! error TS2339: Property 'c' does not exist on type 'Pick'. + } + + export function getBazB(baz: Baz) { + return baz.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Pick'. + } + + \ No newline at end of file diff --git a/tests/baselines/reference/omitTypeTestErrors01.js b/tests/baselines/reference/omitTypeTestErrors01.js new file mode 100644 index 0000000000000..03f1f5cc6b7b6 --- /dev/null +++ b/tests/baselines/reference/omitTypeTestErrors01.js @@ -0,0 +1,44 @@ +//// [omitTypeTestErrors01.ts] +interface Foo { + a: string; + b: number; + c: boolean; +} + +export type Bar = Omit; +export type Baz = Omit; + +export function getBarC(bar: Bar) { + return bar.c; +} + +export function getBazB(baz: Baz) { + return baz.b; +} + + + +//// [omitTypeTestErrors01.js] +"use strict"; +exports.__esModule = true; +function getBarC(bar) { + return bar.c; +} +exports.getBarC = getBarC; +function getBazB(baz) { + return baz.b; +} +exports.getBazB = getBazB; + + +//// [omitTypeTestErrors01.d.ts] +interface Foo { + a: string; + b: number; + c: boolean; +} +export declare type Bar = Omit; +export declare type Baz = Omit; +export declare function getBarC(bar: Bar): any; +export declare function getBazB(baz: Baz): any; +export {}; diff --git a/tests/baselines/reference/omitTypeTestErrors01.symbols b/tests/baselines/reference/omitTypeTestErrors01.symbols new file mode 100644 index 0000000000000..b913e20de4f93 --- /dev/null +++ b/tests/baselines/reference/omitTypeTestErrors01.symbols @@ -0,0 +1,43 @@ +=== tests/cases/compiler/omitTypeTestErrors01.ts === +interface Foo { +>Foo : Symbol(Foo, Decl(omitTypeTestErrors01.ts, 0, 0)) + + a: string; +>a : Symbol(Foo.a, Decl(omitTypeTestErrors01.ts, 0, 15)) + + b: number; +>b : Symbol(Foo.b, Decl(omitTypeTestErrors01.ts, 1, 14)) + + c: boolean; +>c : Symbol(Foo.c, Decl(omitTypeTestErrors01.ts, 2, 14)) +} + +export type Bar = Omit; +>Bar : Symbol(Bar, Decl(omitTypeTestErrors01.ts, 4, 1)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>Foo : Symbol(Foo, Decl(omitTypeTestErrors01.ts, 0, 0)) + +export type Baz = Omit; +>Baz : Symbol(Baz, Decl(omitTypeTestErrors01.ts, 6, 33)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>Foo : Symbol(Foo, Decl(omitTypeTestErrors01.ts, 0, 0)) + +export function getBarC(bar: Bar) { +>getBarC : Symbol(getBarC, Decl(omitTypeTestErrors01.ts, 7, 39)) +>bar : Symbol(bar, Decl(omitTypeTestErrors01.ts, 9, 24)) +>Bar : Symbol(Bar, Decl(omitTypeTestErrors01.ts, 4, 1)) + + return bar.c; +>bar : Symbol(bar, Decl(omitTypeTestErrors01.ts, 9, 24)) +} + +export function getBazB(baz: Baz) { +>getBazB : Symbol(getBazB, Decl(omitTypeTestErrors01.ts, 11, 1)) +>baz : Symbol(baz, Decl(omitTypeTestErrors01.ts, 13, 24)) +>Baz : Symbol(Baz, Decl(omitTypeTestErrors01.ts, 6, 33)) + + return baz.b; +>baz : Symbol(baz, Decl(omitTypeTestErrors01.ts, 13, 24)) +} + + diff --git a/tests/baselines/reference/omitTypeTestErrors01.types b/tests/baselines/reference/omitTypeTestErrors01.types new file mode 100644 index 0000000000000..e7282016868d6 --- /dev/null +++ b/tests/baselines/reference/omitTypeTestErrors01.types @@ -0,0 +1,39 @@ +=== tests/cases/compiler/omitTypeTestErrors01.ts === +interface Foo { + a: string; +>a : string + + b: number; +>b : number + + c: boolean; +>c : boolean +} + +export type Bar = Omit; +>Bar : Pick + +export type Baz = Omit; +>Baz : Pick + +export function getBarC(bar: Bar) { +>getBarC : (bar: Pick) => any +>bar : Pick + + return bar.c; +>bar.c : any +>bar : Pick +>c : any +} + +export function getBazB(baz: Baz) { +>getBazB : (baz: Pick) => any +>baz : Pick + + return baz.b; +>baz.b : any +>baz : Pick +>b : any +} + + diff --git a/tests/baselines/reference/omitTypeTests01.js b/tests/baselines/reference/omitTypeTests01.js new file mode 100644 index 0000000000000..af244b8b02b39 --- /dev/null +++ b/tests/baselines/reference/omitTypeTests01.js @@ -0,0 +1,44 @@ +//// [omitTypeTests01.ts] +interface Foo { + a: string; + b: number; + c: boolean; +} + +export type Bar = Omit; +export type Baz = Omit; + +export function getBarA(bar: Bar) { + return bar.a; +} + +export function getBazA(baz: Baz) { + return baz.a; +} + + + +//// [omitTypeTests01.js] +"use strict"; +exports.__esModule = true; +function getBarA(bar) { + return bar.a; +} +exports.getBarA = getBarA; +function getBazA(baz) { + return baz.a; +} +exports.getBazA = getBazA; + + +//// [omitTypeTests01.d.ts] +interface Foo { + a: string; + b: number; + c: boolean; +} +export declare type Bar = Omit; +export declare type Baz = Omit; +export declare function getBarA(bar: Bar): string; +export declare function getBazA(baz: Baz): string; +export {}; diff --git a/tests/baselines/reference/omitTypeTests01.symbols b/tests/baselines/reference/omitTypeTests01.symbols new file mode 100644 index 0000000000000..d614f65daff03 --- /dev/null +++ b/tests/baselines/reference/omitTypeTests01.symbols @@ -0,0 +1,47 @@ +=== tests/cases/compiler/omitTypeTests01.ts === +interface Foo { +>Foo : Symbol(Foo, Decl(omitTypeTests01.ts, 0, 0)) + + a: string; +>a : Symbol(Foo.a, Decl(omitTypeTests01.ts, 0, 15)) + + b: number; +>b : Symbol(Foo.b, Decl(omitTypeTests01.ts, 1, 14)) + + c: boolean; +>c : Symbol(Foo.c, Decl(omitTypeTests01.ts, 2, 14)) +} + +export type Bar = Omit; +>Bar : Symbol(Bar, Decl(omitTypeTests01.ts, 4, 1)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>Foo : Symbol(Foo, Decl(omitTypeTests01.ts, 0, 0)) + +export type Baz = Omit; +>Baz : Symbol(Baz, Decl(omitTypeTests01.ts, 6, 33)) +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) +>Foo : Symbol(Foo, Decl(omitTypeTests01.ts, 0, 0)) + +export function getBarA(bar: Bar) { +>getBarA : Symbol(getBarA, Decl(omitTypeTests01.ts, 7, 39)) +>bar : Symbol(bar, Decl(omitTypeTests01.ts, 9, 24)) +>Bar : Symbol(Bar, Decl(omitTypeTests01.ts, 4, 1)) + + return bar.a; +>bar.a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15)) +>bar : Symbol(bar, Decl(omitTypeTests01.ts, 9, 24)) +>a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15)) +} + +export function getBazA(baz: Baz) { +>getBazA : Symbol(getBazA, Decl(omitTypeTests01.ts, 11, 1)) +>baz : Symbol(baz, Decl(omitTypeTests01.ts, 13, 24)) +>Baz : Symbol(Baz, Decl(omitTypeTests01.ts, 6, 33)) + + return baz.a; +>baz.a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15)) +>baz : Symbol(baz, Decl(omitTypeTests01.ts, 13, 24)) +>a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15)) +} + + diff --git a/tests/baselines/reference/omitTypeTests01.types b/tests/baselines/reference/omitTypeTests01.types new file mode 100644 index 0000000000000..c07894ee2dcf6 --- /dev/null +++ b/tests/baselines/reference/omitTypeTests01.types @@ -0,0 +1,39 @@ +=== tests/cases/compiler/omitTypeTests01.ts === +interface Foo { + a: string; +>a : string + + b: number; +>b : number + + c: boolean; +>c : boolean +} + +export type Bar = Omit; +>Bar : Pick + +export type Baz = Omit; +>Baz : Pick + +export function getBarA(bar: Bar) { +>getBarA : (bar: Pick) => string +>bar : Pick + + return bar.a; +>bar.a : string +>bar : Pick +>a : string +} + +export function getBazA(baz: Baz) { +>getBazA : (baz: Pick) => string +>baz : Pick + + return baz.a; +>baz.a : string +>baz : Pick +>a : string +} + + From 57938e6cc23ac8f9aededab1adc252b249153407 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 24 Apr 2019 16:57:20 -0700 Subject: [PATCH 3/4] Make `Omit` alias its own mapped type so that references to it never expand to `Pick<...>`. --- src/lib/es5.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index de4a612d3919f..994fb1d765330 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1446,7 +1446,9 @@ type Extract = T extends U ? T : never; /** * Construct a type with the properties of T except for those in type K. */ -type Omit = Pick>; +type Omit = { + [P in Exclude]: T[P] +}; /** * Exclude null and undefined from T From a34f9880ea86901c5fd3a749866e2dd9837560be Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 24 Apr 2019 17:01:28 -0700 Subject: [PATCH 4/4] Accepted baselines. --- .../reference/omitTypeTestErrors01.errors.txt | 8 ++++---- .../reference/omitTypeTestErrors01.types | 16 ++++++++-------- .../baselines/reference/omitTypeTests01.symbols | 8 ++++---- tests/baselines/reference/omitTypeTests01.types | 16 ++++++++-------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/baselines/reference/omitTypeTestErrors01.errors.txt b/tests/baselines/reference/omitTypeTestErrors01.errors.txt index a66ab384b8935..6b65e292b55f4 100644 --- a/tests/baselines/reference/omitTypeTestErrors01.errors.txt +++ b/tests/baselines/reference/omitTypeTestErrors01.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/omitTypeTestErrors01.ts(11,16): error TS2339: Property 'c' does not exist on type 'Pick'. -tests/cases/compiler/omitTypeTestErrors01.ts(15,16): error TS2339: Property 'b' does not exist on type 'Pick'. +tests/cases/compiler/omitTypeTestErrors01.ts(11,16): error TS2339: Property 'c' does not exist on type 'Omit'. +tests/cases/compiler/omitTypeTestErrors01.ts(15,16): error TS2339: Property 'b' does not exist on type 'Omit'. ==== tests/cases/compiler/omitTypeTestErrors01.ts (2 errors) ==== @@ -15,13 +15,13 @@ tests/cases/compiler/omitTypeTestErrors01.ts(15,16): error TS2339: Property 'b' export function getBarC(bar: Bar) { return bar.c; ~ -!!! error TS2339: Property 'c' does not exist on type 'Pick'. +!!! error TS2339: Property 'c' does not exist on type 'Omit'. } export function getBazB(baz: Baz) { return baz.b; ~ -!!! error TS2339: Property 'b' does not exist on type 'Pick'. +!!! error TS2339: Property 'b' does not exist on type 'Omit'. } \ No newline at end of file diff --git a/tests/baselines/reference/omitTypeTestErrors01.types b/tests/baselines/reference/omitTypeTestErrors01.types index e7282016868d6..4b286c2c89cbf 100644 --- a/tests/baselines/reference/omitTypeTestErrors01.types +++ b/tests/baselines/reference/omitTypeTestErrors01.types @@ -11,28 +11,28 @@ interface Foo { } export type Bar = Omit; ->Bar : Pick +>Bar : Omit export type Baz = Omit; ->Baz : Pick +>Baz : Omit export function getBarC(bar: Bar) { ->getBarC : (bar: Pick) => any ->bar : Pick +>getBarC : (bar: Omit) => any +>bar : Omit return bar.c; >bar.c : any ->bar : Pick +>bar : Omit >c : any } export function getBazB(baz: Baz) { ->getBazB : (baz: Pick) => any ->baz : Pick +>getBazB : (baz: Omit) => any +>baz : Omit return baz.b; >baz.b : any ->baz : Pick +>baz : Omit >b : any } diff --git a/tests/baselines/reference/omitTypeTests01.symbols b/tests/baselines/reference/omitTypeTests01.symbols index d614f65daff03..93b492917855a 100644 --- a/tests/baselines/reference/omitTypeTests01.symbols +++ b/tests/baselines/reference/omitTypeTests01.symbols @@ -28,9 +28,9 @@ export function getBarA(bar: Bar) { >Bar : Symbol(Bar, Decl(omitTypeTests01.ts, 4, 1)) return bar.a; ->bar.a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15)) +>bar.a : Symbol(a) >bar : Symbol(bar, Decl(omitTypeTests01.ts, 9, 24)) ->a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15)) +>a : Symbol(a) } export function getBazA(baz: Baz) { @@ -39,9 +39,9 @@ export function getBazA(baz: Baz) { >Baz : Symbol(Baz, Decl(omitTypeTests01.ts, 6, 33)) return baz.a; ->baz.a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15)) +>baz.a : Symbol(a) >baz : Symbol(baz, Decl(omitTypeTests01.ts, 13, 24)) ->a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15)) +>a : Symbol(a) } diff --git a/tests/baselines/reference/omitTypeTests01.types b/tests/baselines/reference/omitTypeTests01.types index c07894ee2dcf6..549fcccc0f2f8 100644 --- a/tests/baselines/reference/omitTypeTests01.types +++ b/tests/baselines/reference/omitTypeTests01.types @@ -11,28 +11,28 @@ interface Foo { } export type Bar = Omit; ->Bar : Pick +>Bar : Omit export type Baz = Omit; ->Baz : Pick +>Baz : Omit export function getBarA(bar: Bar) { ->getBarA : (bar: Pick) => string ->bar : Pick +>getBarA : (bar: Omit) => string +>bar : Omit return bar.a; >bar.a : string ->bar : Pick +>bar : Omit >a : string } export function getBazA(baz: Baz) { ->getBazA : (baz: Pick) => string ->baz : Pick +>getBazA : (baz: Omit) => string +>baz : Omit return baz.a; >baz.a : string ->baz : Pick +>baz : Omit >a : string }