microsoft / microsoft/TypeScript
Update Pick to use new key remapping in mapped types
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
pick omit key remapping
Suggestion
Update Pick in lib.d.ts to be:
type Pick<T, K extends keyof T> = {
[P in keyof T as Extract<P, K>]: T[P];
};
It is currently defined as:
type Pick<T, K extends keyof T> = {
[P in K]: T[P];
};
Use Cases
With this new definition, typescript can statically analyze the keys, which allows interfaces to extends these types.
Examples
interface Base {
a: number,
b: string,
c: boolean,
}
// Errors: "An interface can only extend an object type or intersection of object types with statically known members"
interface PickBase0<K extends keyof Base> extends Pick<Base, K> {
pickedKeys: K
}
type Pick1<T, K extends keyof T> = { [L in keyof T as Extract<L, K>]: T[L] }
// Works
interface PickBase1<K extends keyof Base> extends Pick1<Base, K> {
pickedKeys: K
}
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 esaminando la definizione corrente di Pick in lib.d.ts e riproduci l’esempio collegato di Playground che coinvolge tipi mappati ed estensione di interfacce. Confronta la definizione proposta per il rimappamento delle chiavi con il comportamento esistente; il lavoro è completato quando l’esempio funziona senza interrompere il comportamento esistente di Pick e i controlli TypeScript pertinenti hanno esito positivo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100