Skip to content
New issue

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

Utility Type Request: DeepUndefinedToNull #641

Open
dawidk92 opened this issue Jun 22, 2023 · 2 comments · May be fixed by #648
Open

Utility Type Request: DeepUndefinedToNull #641

dawidk92 opened this issue Jun 22, 2023 · 2 comments · May be fixed by #648

Comments

@dawidk92
Copy link

dawidk92 commented Jun 22, 2023

I am working on a TypeScript project where I need to transform a type with optional properties into a type where the optional properties are replaced with union types that include null. For example, I would like to transform this type A:

interface A {
  a?: string;
  b?: { c?: number };
  d: boolean;
}

into this type B:

interface B {
  a: string | null;
  b: { c: number | null } | null;
  d: boolean;
}

Furthermore, I would like this utility type to also support property access, such that the following code:

type C = DeepUndefinedToNull<A["a"]>

returns a type C equivalent to string | null.

Despite extensive efforts and even assistance from OpenAI's GPT model, I've been unable to create a utility type that achieves this. I believe this could be a valuable addition to type-fest and would be useful for many TypeScript developers who need to handle optional properties in this way.

Would you please consider adding such a utility type to type-fest? Thank you for your time and consideration.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@ahrjarrett ahrjarrett linked a pull request Jul 15, 2023 that will close this issue
@ahrjarrett
Copy link
Contributor

Hey @dawidk92 , wanted to let you know that I opened a PR implementing this request. It's a pretty solid implementation IMO, and as a bonus it also handles union types. Definitely open to feedback if you want to give it a go!

@sindresorhus
Copy link
Owner

#648 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants