microsoft / microsoft/TypeScript
`readonly` mapped type modifiers for `Map` / `ReadonlyMap`
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
ReadonlyMap
ReadWrite
Writable
Suggestion
3.4.0-rc introduced the ability to use readonly mapped type modifiers with arrays.
(https://devblogs.microsoft.com/typescript/announcing-typescript-3-4-rc/)
It would be useful if the same syntax worked on
Use Cases
This is useful in any library dealing with immutable versions of types. It would allow mapped types to easily convert between Map and ReadonlyMap.
Examples
type ReadWrite<T> = { -readonly [P in keyof T]: T[P] };
const map: ReadWrite<ReadonlyMap<string, string>> = new Map();
map.put('a', 'c'); // this should work, since readonly has been removed.
type Readonly<T> = { readonly [P in keyof T]: T[P] };
const map: Readonly<Map<string, string>> = new Map();
map.put('a', 'c'); // this should not work, since readonly has been applied
Similar examples using Array instead of Map didn't work before 3.4 and did work afterwards.
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
Inizia riproducendo gli esempi di tipi mappati ReadWrite e Readonly dell'issue e confronta il loro comportamento con quello di Array introdotto in TypeScript 3.4. Traccia la gestione dei tipi mappati nel compilatore per determinare il design richiesto; il lavoro è completato quando gli esempi di Map/ReadonlyMap si comportano come specificato senza modificare il JavaScript emesso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- 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
- 25/100