microsoft / microsoft/TypeScript
Anonymous Symbol Properties
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
### 🔍 Search Terms
"anonymous symbol properties"
"anonymous unique symbol"
"inline unique symbol"
"unique symbol property key"
"computed property unique symbol"
"symbol branding"
### ✅ Viability Checklist
- [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
- [x] This wouldn't change the runtime behavior of existing JavaScript code
- [x] This could be implemented without emitting different JS based on the types of the expressions
- [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- [x] This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- [x] This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
### ⭐ Suggestion
Allow `unique symbol` keys to be declared inline at the property declaration site.
### 📃 Motivating Example
**Current code:**
```ts
declare const brand: unique symbol;
type UserId = string & { readonly [brand]: "UserId" };
```
**Proposed code:**
```ts
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con las declaraciones de tipos actuales y propuestas en el issue y rastrea cómo TypeScript gestiona las claves de propiedad calculadas y las identidades de unique symbol. Se considera terminado cuando se acepten claves de propiedad inline de tipo unique symbol, cada declaración reciba una identidad nueva y se conserve la salida de JavaScript en tiempo de ejecución; el issue no menciona archivos de implementación ni pruebas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Activo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100