type-fest
type-fest copied to clipboard
[Proposal] SetNonNullable
I honestly thought SetRequired
did this. example of expected behavior
type Optional<T> = T | undefined | null;
type Foo = {
bar: Optional<string>;
foo?: string | null;
baz?: string;
};
type NonNullableFoo = SetNonNullable<Foo, 'bar' | 'foo'>;
// would be equivalent to
type ManualNonNullableFoo = {
bar: string;
foo: string;
baz?: string;
};
I honestly thought SetRequired did this.
⬇️
Create a type that makes the given keys required.
This seems useful though. I wonder if we could just overwrite the built-in NonNullable
version with a more powerful one that also accepts which keys to apply to, as discussed in https://github.com/sindresorhus/type-fest/issues/171.
@sindresorhus However, note that SetRequired
does more than just mark the given keys as required - it also strips undefined
from them.
I believe this can be closed now that https://github.com/sindresorhus/type-fest/pull/431 has been merged?