Skip to content

Removing 'optional' attributes from a type's properties disallow adding undefined as it's typeΒ #46850

Closed as not planned
@KuSh

Description

@KuSh

Bug Report

πŸ”Ž Search Terms

type generic remove optional attribute

πŸ•— Version & Regression Information

I did test this on 4.4.4 and 4.5.0-beta using playground

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type NullableType<T> = {
    [K in keyof T]-?: undefined extends T[K]
    ? T[K] | null | undefined
    : T[K]
}

πŸ™ Actual behavior

Removing optional attribute from type also remove undefined from final type
(when not removing optional attribute, final type is x?: typeof x | null | undefined)

πŸ™‚ Expected behavior

Removing optional attribute just removes the optional attribute and doesn't modify final type

Metadata

Metadata

Assignees

No one assigned

    Labels

    UnactionableThere isn't something we can do with this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions