microsoft / microsoft/TypeScript
Infer type when object coerced to string if toString explicitly defined
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
Search Terms
coercion toString computed properties
Suggestion
Infer type when object coerced to string if toString explicitly defined
Examples
Would be nice if the following would be allowed
const action = {
type: 'foo',
toString() { return this.type }
} as const;
const reducerHandler = {
[action]: () => { } // Currently errors: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
}
Checklist
My suggestion meets these guidelines:
- 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, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
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.
Direzione di ricerca
Esegui l'esempio collegato di TypeScript Playground ed esamina l'errore attuale relativo al nome di proprietà calcolato. Determina in che modo le definizioni esplicite di toString dovrebbero influire sul controllo dei tipi, quindi verifica che l'esempio venga accettato senza modificare il JavaScript emesso e che venga aggiunta la coverage per questo comportamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100