We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Omit
omit union broaden types
Playground link with relevant code
type Schedule = | { scheduled: true; scheduleTime: number; } | { scheduled: false; scheduleTime: null; }; type Item = { id: number; name: string; } & Schedule; // id is auto-generated // // From inspection, CreateItemData is equivalent to // type CreateItemData = { // name: string; // scheduled: boolean; // scheduleTime: number | null; // } type CreateItemData = Omit<Item, "id">; const data: CreateItemData = { name: "item name", scheduled: true, scheduleTime: null, }; // @ts-expect-error: This works correctly const scheduleData: Schedule = { scheduled: true, scheduleTime: null, };
The line const data: CreateItemData = ... typechecks, as CreateItemData throws away some important data about Schedule type.
const data: CreateItemData = ...
CreateItemData
Schedule
The line const data: CreateItemData = ... should not typecheck, CreateItemData should be equal to
type CreateItemData = | { name: string; scheduled: true; scheduleTime: number; } | { name: string; scheduled: false; scheduleTime: null; };
The text was updated successfully, but these errors were encountered:
Omit does not distribute over unions. See #49659 (comment)
Sorry, something went wrong.
Thanks for pointing me to #49659. @RyanCavanaugh Should we bring DistributedOmit into TS's core utility types?
DistributedOmit
Should we bring DistributedOmit into TS's core utility types?
See #39522 (comment):
We've opted to not include utility type aliases in the lib unless they're required for declaration emit purposes.
Also #49656 (comment):
One of the reasons we don't like adding type aliases to the built-in lib -- we can't "upgrade" them!
No branches or pull requests
Bug Report
π Search Terms
omit union broaden types
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
The line
const data: CreateItemData = ...
typechecks, asCreateItemData
throws away some important data aboutSchedule
type.π Expected behavior
The line
const data: CreateItemData = ...
should not typecheck,CreateItemData
should be equal toThe text was updated successfully, but these errors were encountered: