microsoft / microsoft/TypeScript
TypedPropertyDescriptorMap<T>
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza localizando la declaración de Object.defineProperties y los tipos existentes TypedPropertyDescriptor y PropertyDescriptorMap. Revisa el issue relacionado #15300 y, a continuación, verifica el mapped type propuesto y su aceptación por parte de Object.defineProperties mediante una prueba de type-checking enfocada; se considera terminado cuando los descriptor maps tipados funcionan sin el index-signature error.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 43/100