type-fest icon indicating copy to clipboard operation
type-fest copied to clipboard

[Proposal] SetNonNullable

Open xenoterracide opened this issue 4 years ago • 3 comments

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;
};

xenoterracide avatar Nov 12 '20 09:11 xenoterracide

I honestly thought SetRequired did this.

⬇️

Create a type that makes the given keys required.

sindresorhus avatar Dec 20 '20 13:12 sindresorhus

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 avatar Dec 20 '20 13:12 sindresorhus

@sindresorhus However, note that SetRequired does more than just mark the given keys as required - it also strips undefined from them.

papb avatar Dec 20 '20 20:12 papb

I believe this can be closed now that https://github.com/sindresorhus/type-fest/pull/431 has been merged?

joealden avatar Sep 06 '22 11:09 joealden