microsoft / microsoft/TypeScript
Type variables in TypedPropertyDescriptor cause compilation errors when using decorator
Abierto
@rbuckton ya está trabajando en esto.
Desde el 17/9/2019.
Needs Investigation
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
TypeScript Version: 3.6.3
Search Terms: TypedPropertyDescriptor, MethodDecorator, TS2345, Types of property 'value' are incompatible.
Code
type MyDynamicDescriptor = <T>(input: T) => T
type MyStaticDescriptor = (input: number) => number
function dynamicDecorator(foo: string) {
return (_: any, __: any, descriptor: TypedPropertyDescriptor<MyDynamicDescriptor>) => {
console.log('foo:', foo)
console.log('descriptor.value:', descriptor.value)
}
}
function staticDecorator(foo: string) {
return (_: any, __: any, descriptor: TypedPropertyDescriptor<MyStaticDescriptor>) => {
console.log('foo:', foo)
console.log('descriptor.value:', descriptor.value)
}
}
class myClass {
@dynamicDecorator('bar')
myMethod(input: number): number {
return input + 42
}
@staticDecorator('bar')
myOtherMethod(input: number): number {
return input + 42
}
}
Expected behavior:
No compilation errors for both dynamicDecorator and staticDecorator.
Actual behavior:
Compilation errors for dynamicDecorator:
error TS2345: Argument of type 'TypedPropertyDescriptor<(input: number) => Promise<number>>' is not assignable to parameter of type 'TypedPropertyDescriptor<MyDynamicDescriptor>'.
Types of property 'value' are incompatible.
Type '((input: number) => Promise<number>) | undefined' is not assignable to type 'MyDynamicDescriptor | undefined'.
Type '(input: number) => Promise<number>' is not assignable to type 'MyDynamicDescriptor'.
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.
Evaluación
Este issue todavía no se ha evaluado.