microsoft / microsoft/TypeScript
Type variables in TypedPropertyDescriptor cause compilation errors when using decorator
Open
@rbuckton is already working on this.
Since Sep 17, 2019.
Needs Investigation
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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'.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.