microsoft / microsoft/TypeScript
TypedPropertyDescriptorMap<T>
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die Deklaration für Object.defineProperties sowie die vorhandenen Typen TypedPropertyDescriptor und PropertyDescriptorMap zu finden. Prüfe anschließend das zugehörige Issue #15300 und verifiziere dann den vorgeschlagenen mapped type und dessen Akzeptanz durch Object.defineProperties mit einem gezielten type-checking test; fertig ist die Aufgabe, wenn typisierte descriptor maps ohne den index-signature error funktionieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 43/100