microsoft / microsoft/TypeScript
TypedPropertyDescriptorMap<T>
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
TypedPropertyDescriptor
TypedPropertyDescriptorMap
Typed Property Descriptor Map
Suggestion
Include TypedPropertyDescriptorMap<T>, the typed version of PropertyDescriptorMap. The following type should do the trick:
type TypedPropertyDescriptorMap<T> = {
[P in keyof T]: TypedPropertyDescriptor<T[P]>
}
This would require a change to the Object.defineProperties type definition since it only accepts a PropertyDescriptorMap type, an indexed type. Passing in an object with a type of TypedPropertyDescriptorMap<T> results in the error: Index signature is missing in type 'TypedPropertyDescriptorMap<T>'. There's a related issue on this topic (https://github.com/Microsoft/TypeScript/issues/15300).
Use Cases
It's a headache to have to define a type like the following when I already have defined the final object type:
// Final object looks like
interface MyProps {
prop1: string
prop2: (params: Record<string, string>) => Promise<void>
}
// My custom TypedPropertyDescriptor map
interface MyPropDescriptors {
prop1: TypedPropertyDescriptor<MyProps['prop1']>
prop2: TypedPropertyDescriptor<MyProps['prop2']>
...
}
Examples
// Final object looks like
interface MyProps {
prop1: string
prop2: (params: Record<string, string>) => Promise<void>
}
// My custom TypedPropertyDescriptor map
type MyPropDescriptors = TypedPropertyDescriptorMap<MyProps>
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 individuando la dichiarazione di Object.defineProperties e i tipi esistenti TypedPropertyDescriptor e PropertyDescriptorMap. Esamina quindi la issue correlata #15300, poi verifica il mapped type proposto e la sua accettazione da parte di Object.defineProperties con un test di type-checking mirato; il lavoro è completo quando le descriptor maps tipizzate funzionano senza l’index-signature error.
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
- Abbastanza chiara
- Idoneità per principianti
- 43/100