Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Unique typeΒ #59431

Copy link
Copy link
Open
Open
Copy link
@ruojianll

Description

@ruojianll
Issue body actions

πŸ” Search Terms

"unique type"

βœ… Viability Checklist

⭐ Suggestion

Sometimes I just need a unique type as flags in my type calculations. If I use a string subtype or others it couldn't be identity well. Such as:

type Flag = 'Flag'
type MyType<T extends string|Flag>=T extends Flag? 'IsFlag':'A normal string'

In the code, Flag is also a string. I don't want to post some complex types which references each other and using flag types but it is really useful for me.
Define a pure unique type without any runtime content.

πŸ“ƒ Motivating Example

type Flag1 = unique('Flag')
type Flag2 = unique('Flag')

Flag1 is not Flag2 like unique symbols.
The unique types only extends itself for checking what it is.
Pass a text to unique keyword to create a unique type.

πŸ’» Use Cases

  1. What do you want to use this for?
    To control the type calculation especially in recursive type definitions.
  2. What shortcomings exist with current approaches?
    If I define a unique symbol, it should produce a runtime symbol.
  3. What workarounds are you using in the meantime?
    Write flag with string sub-type carefully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.