Skip to content

Anonymous Symbol PropertiesΒ #64253

Description

πŸ” Search Terms

"anonymous symbol properties"
"anonymous unique symbol"
"inline unique symbol"
"unique symbol property key"
"computed property unique symbol"
"symbol branding"

βœ… Viability Checklist

⭐ Suggestion

Allow unique symbol keys to be declared inline at the property declaration site.

πŸ“ƒ Motivating Example

Current code:

declare const brand: unique symbol;
type UserId = string & { readonly [brand]: "UserId" };

Proposed code:

type UserId = string & { readonly [brand: unique symbol]: "UserId" };

Each inline declaration would create a fresh symbol identity, equivalent to declaring a separate unique symbol and using it as the computed property key.

This is useful when a unique symbol property key is needed only once and does not need to be referenced independently. Common examples include phantom properties used for branded or refined types.

πŸ’» Use Cases

  1. What do you want to use this for?
    Declaring single-use unique symbol property keys inline, particularly for phantom properties used by branded or refined types.

  2. What shortcomings exist with current approaches?
    The current approach requires introducing a value-level declaration solely to provide a unique identity for a type-level property key. For single-use symbol keys, this creates an otherwise unnecessary binding in the surrounding scope.

  3. What workarounds are you using in the meantime?
    Declaring a separate unique symbol value and using it as a computed property key.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions