Reputation: 6236
I have the following function –
function wrapper(callback) {
// operation
}
I need the return type of wrapper
to be the same as the first(only) argument passed to callback
. For eg.
wrapper(({paramA, paramB}) => {})
// returns { paramA: somveVal, paramB: someVal }
Is that even possible?
Upvotes: 0
Views: 73
Reputation: 638
function wrapper<T>(callback: T => mixed): T { ...}
Note that this signature is unimplementable unless you didn't actually want it to be generic.
Upvotes: 1
Reputation: 2384
If i understand well, you need something like this:
For example declare type CallBack
:
type CallBack = {|
paramA: any,
paramB: any,
// Or use other type instead any.
|}
And annotate
function:
const wrapper = (fn: (x: CallBack) => CallBack): CallBack => ({ paramA: 1, paramB: 2 });
Flow example: Flow Try
Upvotes: 0