Anonymous Symbol Properties
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- compilers
Direzione di ricerca
Parti dalle dichiarazioni di tipo attuali e proposte nell’issue e segui il modo in cui TypeScript gestisce le chiavi di proprietà calcolate e le identità di unique symbol. Il lavoro è completato quando vengono accettate le chiavi di proprietà inline di tipo unique symbol, ogni dichiarazione riceve una nuova identità e l’output JavaScript a runtime viene preservato; l’issue non indica file di implementazione né test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
🔍 Search Terms
"anonymous symbol properties"
"anonymous unique symbol"
"inline unique symbol"
"unique symbol property key"
"computed property unique symbol"
"symbol branding"
✅ Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- 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:
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
-
What do you want to use this for?
Declaring single-useunique symbolproperty keys inline, particularly for phantom properties used by branded or refined types. -
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. -
What workarounds are you using in the meantime?
Declaring a separateunique symbolvalue and using it as a computed property key.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/TypeScript
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
microsoft/TypeScript#64322 · 2 commenti · 1 reazione · 2 assegnatari ·
-
Possible Improvement
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
microsoft/TypeScript#64278 · 1 commento · 1 reazione ·
-
Docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
microsoft/TypeScript#64118 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
microsoft/TypeScript#64094 ·
-
Docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
microsoft/TypeScript#63959 · 5 commenti ·
Tutte le issue di microsoft/TypeScript
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
milvus-io/birdwatcher#545 ·
-
kind/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
kubernetes-sigs/prow#953 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
caddyserver/caddy#8046 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
jaegertracing/jaeger#9588 ·