Skip to content

[typescript] Add additional Types for possible null values #7451

Open
@sschneider-ihre-pvs

Description

@sschneider-ihre-pvs

Is your feature request related to a problem? Please describe.

So there is the Maybe type already which says the value can be null which actually is more like Nullable if you ask me. Anyway, so the value may be null but if it is optional it also does not need to exist at all, so you either have ? or | undefined added to the Maybe which could be shorter with adding an extra type for that.

Describe the solution you'd like
So additionally to the Maybe utility type lets have something like Nullable (😁 ) which is something like type Nullable<T> = Maybe<T> | undefined = T | null | undefined
Or if you want some other intermediate type maybe something like

type Nothing = null | undefined
type Nullable<T> = T | Nothing

Additional context
Let's have a look at validation lib Zod for a moment. You have the option to use .nullable() and chain .optional() as well, but there is a short form for this which is called .nullish()

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreRelated to codegen core/clikind/enhancementNew feature or requestkind/questionImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions