Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

.omit does not work with unions #53

Closed
mrazauskas opened this issue Feb 27, 2024 · 3 comments · Fixed by #54
Closed

.omit does not work with unions #53

mrazauskas opened this issue Feb 27, 2024 · 3 comments · Fixed by #54

Comments

@mrazauskas
Copy link
Contributor

Playground link.

Take a look at the following example. Omit works as expected, but .omit fails:

import {expectTypeOf} from 'expect-type'

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'}>()
                                   // ^^^^^^ Type '"code"' does not satisfy the constraint '"state"'.
@mmkal
Copy link
Owner

mmkal commented Mar 10, 2024

@mrazauskas thanks for reporting. Note that Omit<...> doesn't seem to have any extends constraints at all (e.g. Omit<{a: 1}, 'b'> is allowed), so this will take away type hinting at which keys could/should be omitted. But I agree it's better to match Omit.

Would you be interested in submitting a pull request?

@mrazauskas
Copy link
Contributor Author

@aryaemami59 Perhaps you would be interested to take a second look at the implementation?

@aryaemami59
Copy link
Collaborator

aryaemami59 commented Mar 11, 2024

@mrazauskas

@aryaemami59 Perhaps you would be interested to take a second look at the implementation?

Yes absolutely, I will take a look!

aryaemami59 added a commit to aryaemami59/expect-type that referenced this issue Mar 11, 2024
@mmkal mmkal closed this as completed in #54 Mar 13, 2024
mmkal pushed a commit that referenced this issue Mar 13, 2024
## 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.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants