Skip to content

Commit

Permalink
Fix .omit() to work similarly to Omit (#54)
Browse files Browse the repository at this point in the history
## This PR:

- [X] Fixes `.omit()` to work similarly to `Omit`. This was done in a
way that allows type hinting and intellisense to work without being too
strict.
  - [X] Resolves #53.
  • Loading branch information
aryaemami59 authored Mar 13, 2024
1 parent 2ab099c commit ab32eb4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export interface PositiveExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
toEqualTypeOf: {
/**
* Uses typescript's internal technique to check for type "identicalness".
*
*
* **_Unexpected failure_**? For a more permissive but less performant check that accomodates
* for equivalent intersection types, use `.branded`. See [the documentation for details](https://github.com/mmkal/expect-type#why-is-my-assertion-failing).
*/
Expand All @@ -250,7 +250,7 @@ export interface PositiveExpectTypeOf<Actual> extends BaseExpectTypeOf<Actual, {
): true
/**
* Uses typescript's internal technique to check for type "identicalness".
*
*
* **Unexpected failure**? For a more permissive but less performant check that accomodates
* for equivalent intersection types, use `.branded`. See [the documentation for details](https://github.com/mmkal/expect-type#why-is-my-assertion-failing).
*/
Expand Down Expand Up @@ -339,7 +339,7 @@ export interface BaseExpectTypeOf<Actual, Options extends {positive: boolean}> {
extract: <V>(v?: V) => ExpectTypeOf<Extract<Actual, V>, Options>
exclude: <V>(v?: V) => ExpectTypeOf<Exclude<Actual, V>, Options>
pick: <K extends keyof Actual>(v?: K) => ExpectTypeOf<Pick<Actual, K>, Options>
omit: <K extends keyof Actual>(v?: K) => ExpectTypeOf<Omit<Actual, K>, Options>
omit: <K extends keyof Actual | (PropertyKey & Record<never, never>)>(v?: K) => ExpectTypeOf<Omit<Actual, K>, Options>
parameter: <K extends keyof Params<Actual>>(number: K) => ExpectTypeOf<Params<Actual>[K], Options>
parameters: ExpectTypeOf<Params<Actual>, Options>
constructorParameters: ExpectTypeOf<ConstructorParams<Actual>, Options>
Expand Down
17 changes: 17 additions & 0 deletions test/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,3 +714,20 @@ test('PrintType', () => {
expectTypeOf<a.PrintType<() => {}>>().toEqualTypeOf<'function'>()
expectTypeOf<a.PrintType<any>>().toBeNever()
})

test('Issue #53: `.omit()` should work similarly to `Omit`', () => {
// https://github.com/mmkal/expect-type/issues/53

type Loading = {
state: 'loading'
}

type Failed = {
state: 'failed'
code: number
}

expectTypeOf<Omit<Loading | Failed, 'code'>>().toEqualTypeOf<{state: 'loading' | 'failed'}>()

expectTypeOf<Loading | Failed>().omit<'code'>().toEqualTypeOf<{state: 'loading' | 'failed'}>()
})

0 comments on commit ab32eb4

Please sign in to comment.