Implement flow for decorators (method decorators)
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Decorators are heavily used. Currently you can disable warning, but there is zero flow support for function signature of the decorator arguments.
There are other experimental functions in flow already which are handled correctly though.
So decorator argument and return type - typing support would be basic and nice.
If flow could handle value remapping - it were be even better. Since the return type (Attributes) can be predicted, it can be static analysed.
```JS
function decoratorA(target: Object, prop: string, attributes: PropertyAttributes) {
// ... set value or getter, setter...
// PropertyAttributes
// value: any
// set(any)
// get(): any
attributes.value
// must return a new attributes object because attributes is already PropertyAttributes and it cannot be altered
return {
value: function(a: string, b: boolean) {
return true;
}, // flow analyse the type as: (a: string, b: string) => boolean
// set this signature as the new signature for the method
// follow up decorators now receives this type
// example: PropertyAttributes
// get/set for property decorator
}
}
class A {
@decoratorA // new signature: ()
function() {
return 123;
}
}
```
Especially if you call the instance method from outside, it should show the correct signature (last set PropertyDescriptor)
So I wondering this is possible with the current flow source code or if there some bricks?!
Contributor guide
Assessment
This issue has not been assessed yet.