Skip to content

enable type guards over string literal types #6028

Closed
@zpdDG4gta8XKpMCd

Description

@zpdDG4gta8XKpMCd

Now that the string literal types #5185 are merged in, the type guards based on them would be an awesome addition:

by @ahejlsberg:

Type guards could relate the common kind property to the corresponding object type in the union and narrow the type appropriately in the guarded block.

The original issue #1003 got closed with the following comment:

the remaining part is extending the type guards to support the string literal types. but this should be tracked by a different issue.

A quick search suggests that there isn't a ticket for this yet. So here we go.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CommittedThe team has roadmapped this issueDomain: Literal TypesUnit types including string literal types, numeric literal types, Boolean literals, null, undefinedFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions