I have a common need to omit key-values pairs based on the value, for instance removing undefined
or null
values from an object, similar to this Stack Overflow question.
It would be cool if there were a type that could easily be used that behaved like so:
type Foo = { foo: number | null, bar?: string, baz: undefined };
type WithoutUndefined = OmitValues<Foo, undefined> // { foo: number | null, bar: string } # NOTE: I think it should remove optionality in this case, but maybe that's subjective
type WithoutUndefinedOrNull = OmitValues<Foo, undefined | null> // { foo: number, bar: string }
type WithoutNumbers = OmitValues<Foo, number> // { foo: null, bar?: string, baz: undefined }
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too