const a = (a: string) => { }
const b = (...args: Parameters<typeof a>) {
}
// TS says x is any here, that's why it doesn't work as expected
const c = (x) => (...args: Parameters<typeof x>) => {
}
const d = <T>(...args: Parameters<T>) => {
}
// works:
b()
// doesnt work. i would like to get this working
c(a)(1)
// dont want this solution
d<typeof a>(1)
x is any because you're not explicitly giving it a type. If you want behavior where the next function call infers its argument type based on the previous, then you can do something like:
const c = <T extends (...args: any[]) => any>(x: T) => (...args: Parameters<T>) => {}
and then when you put in c(a) typescript infers the next function as (a: string) => void
Wow you are genius! it really works! thanks you !!!
Most helpful comment
x is any because you're not explicitly giving it a type. If you want behavior where the next function call infers its argument type based on the previous, then you can do something like:
and then when you put in c(a) typescript infers the next function as
(a: string) => void