microsoft / microsoft/TypeScript
TypedPropertyDescriptorMap<T>
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
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.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par localiser la déclaration de Object.defineProperties ainsi que les types existants TypedPropertyDescriptor et PropertyDescriptorMap. Examinez ensuite l’issue associée #15300, puis vérifiez le mapped type proposé et son acceptation par Object.defineProperties au moyen d’un test de type-checking ciblé ; le travail est terminé lorsque les descriptor maps typés fonctionnent sans l’index-signature error.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript
- Domaine
- compilers
- Type d'issue
- Fonctionnalité
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 43/100