sindresorhus / type-fest

A collection of essential TypeScript types
Creative Commons Zero v1.0 Universal
14.2k stars 538 forks source link

[FR] SetNullable #697

Open risalfajar opened 1 year ago

risalfajar commented 1 year ago

Can we get SetNullable as the opposite of SetNonNullable?

Upvote & Fund

Fund with Polar

filipekiss commented 1 year ago

Doesn't SetOptional does what you need?

risalfajar commented 1 year ago

It doesn't, optional is different than null

Zaporozhec7 commented 1 year ago

I have used this for now, in case it would be useful for someone:

import { Simplify, Except } from "type-fest";

type SetNullable<BaseType, Keys extends keyof BaseType> =
Simplify<
    Except<BaseType, Keys> &
    {
        [K in Keys]: BaseType[K] | null;
    }
>;
risalfajar commented 1 year ago

@Zaporozhec7 Would you please create a PR to add this to the library?

Zaporozhec7 commented 1 year ago

@Zaporozhec7 Would you please create a PR to add this to the library?

I think it better to wait first for some maintainer opinion on the addition of such a type, or PR may be just rejected