Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
Omit
alias a separate type (#31115)
Make `Omit` alias a separate type
- Loading branch information
Showing
10 changed files
with
324 additions
and
1 deletion.
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
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,27 @@ | ||
tests/cases/compiler/omitTypeTestErrors01.ts(11,16): error TS2339: Property 'c' does not exist on type 'Omit<Foo, "c">'. | ||
tests/cases/compiler/omitTypeTestErrors01.ts(15,16): error TS2339: Property 'b' does not exist on type 'Omit<Foo, "c" | "b">'. | ||
|
||
|
||
==== tests/cases/compiler/omitTypeTestErrors01.ts (2 errors) ==== | ||
interface Foo { | ||
a: string; | ||
b: number; | ||
c: boolean; | ||
} | ||
|
||
export type Bar = Omit<Foo, "c">; | ||
export type Baz = Omit<Foo, "b" | "c">; | ||
|
||
export function getBarC(bar: Bar) { | ||
return bar.c; | ||
~ | ||
!!! error TS2339: Property 'c' does not exist on type 'Omit<Foo, "c">'. | ||
} | ||
|
||
export function getBazB(baz: Baz) { | ||
return baz.b; | ||
~ | ||
!!! error TS2339: Property 'b' does not exist on type 'Omit<Foo, "c" | "b">'. | ||
} | ||
|
||
|
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,44 @@ | ||
//// [omitTypeTestErrors01.ts] | ||
interface Foo { | ||
a: string; | ||
b: number; | ||
c: boolean; | ||
} | ||
|
||
export type Bar = Omit<Foo, "c">; | ||
export type Baz = Omit<Foo, "b" | "c">; | ||
|
||
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<Foo, "c">; | ||
export declare type Baz = Omit<Foo, "b" | "c">; | ||
export declare function getBarC(bar: Bar): any; | ||
export declare function getBazB(baz: Baz): any; | ||
export {}; |
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,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<Foo, "c">; | ||
>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<Foo, "b" | "c">; | ||
>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)) | ||
} | ||
|
||
|
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,39 @@ | ||
=== tests/cases/compiler/omitTypeTestErrors01.ts === | ||
interface Foo { | ||
a: string; | ||
>a : string | ||
|
||
b: number; | ||
>b : number | ||
|
||
c: boolean; | ||
>c : boolean | ||
} | ||
|
||
export type Bar = Omit<Foo, "c">; | ||
>Bar : Omit<Foo, "c"> | ||
|
||
export type Baz = Omit<Foo, "b" | "c">; | ||
>Baz : Omit<Foo, "c" | "b"> | ||
|
||
export function getBarC(bar: Bar) { | ||
>getBarC : (bar: Omit<Foo, "c">) => any | ||
>bar : Omit<Foo, "c"> | ||
|
||
return bar.c; | ||
>bar.c : any | ||
>bar : Omit<Foo, "c"> | ||
>c : any | ||
} | ||
|
||
export function getBazB(baz: Baz) { | ||
>getBazB : (baz: Omit<Foo, "c" | "b">) => any | ||
>baz : Omit<Foo, "c" | "b"> | ||
|
||
return baz.b; | ||
>baz.b : any | ||
>baz : Omit<Foo, "c" | "b"> | ||
>b : any | ||
} | ||
|
||
|
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,44 @@ | ||
//// [omitTypeTests01.ts] | ||
interface Foo { | ||
a: string; | ||
b: number; | ||
c: boolean; | ||
} | ||
|
||
export type Bar = Omit<Foo, "c">; | ||
export type Baz = Omit<Foo, "b" | "c">; | ||
|
||
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<Foo, "c">; | ||
export declare type Baz = Omit<Foo, "b" | "c">; | ||
export declare function getBarA(bar: Bar): string; | ||
export declare function getBazA(baz: Baz): string; | ||
export {}; |
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,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<Foo, "c">; | ||
>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<Foo, "b" | "c">; | ||
>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) | ||
>bar : Symbol(bar, Decl(omitTypeTests01.ts, 9, 24)) | ||
>a : Symbol(a) | ||
} | ||
|
||
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) | ||
>baz : Symbol(baz, Decl(omitTypeTests01.ts, 13, 24)) | ||
>a : Symbol(a) | ||
} | ||
|
||
|
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,39 @@ | ||
=== tests/cases/compiler/omitTypeTests01.ts === | ||
interface Foo { | ||
a: string; | ||
>a : string | ||
|
||
b: number; | ||
>b : number | ||
|
||
c: boolean; | ||
>c : boolean | ||
} | ||
|
||
export type Bar = Omit<Foo, "c">; | ||
>Bar : Omit<Foo, "c"> | ||
|
||
export type Baz = Omit<Foo, "b" | "c">; | ||
>Baz : Omit<Foo, "c" | "b"> | ||
|
||
export function getBarA(bar: Bar) { | ||
>getBarA : (bar: Omit<Foo, "c">) => string | ||
>bar : Omit<Foo, "c"> | ||
|
||
return bar.a; | ||
>bar.a : string | ||
>bar : Omit<Foo, "c"> | ||
>a : string | ||
} | ||
|
||
export function getBazA(baz: Baz) { | ||
>getBazA : (baz: Omit<Foo, "c" | "b">) => string | ||
>baz : Omit<Foo, "c" | "b"> | ||
|
||
return baz.a; | ||
>baz.a : string | ||
>baz : Omit<Foo, "c" | "b"> | ||
>a : string | ||
} | ||
|
||
|
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,19 @@ | ||
// @declaration: true | ||
|
||
interface Foo { | ||
a: string; | ||
b: number; | ||
c: boolean; | ||
} | ||
|
||
export type Bar = Omit<Foo, "c">; | ||
export type Baz = Omit<Foo, "b" | "c">; | ||
|
||
export function getBarC(bar: Bar) { | ||
return bar.c; | ||
} | ||
|
||
export function getBazB(baz: Baz) { | ||
return baz.b; | ||
} | ||
|
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,19 @@ | ||
// @declaration: true | ||
|
||
interface Foo { | ||
a: string; | ||
b: number; | ||
c: boolean; | ||
} | ||
|
||
export type Bar = Omit<Foo, "c">; | ||
export type Baz = Omit<Foo, "b" | "c">; | ||
|
||
export function getBarA(bar: Bar) { | ||
return bar.a; | ||
} | ||
|
||
export function getBazA(baz: Baz) { | ||
return baz.a; | ||
} | ||
|