I'm currently facing a challenge involving deeply nested parameters.
When dealing with non-nested parameters, everything functions smoothly without any issues
export type test = {
'fnc1': () => void,
'fnc2': () => void,
'fnc3': () => void,
'fnc4': () => void,
}
export type FncParams<key extends keyof test> = Parameters<test[key]>;
However, upon attempting to work with deep nesting, I encounter a TypeScript error. It's important to note that the typing works fine for code hinting despite the compilation error.
export type testDeep = {
'key1': {
'fnc1': () => void,
'fnc2': () => void,
},
'key2': {
'fnc3': () => void,
'fnc4': () => void,
}
}
export type FncDeepParams<
key extends keyof testDeep,
event extends keyof testDeep[key]
> = Parameters<testDeep[key][event]>;
Type 'testDeep[key][event]' does not satisfy the constraint '(...args: any) => any'.
Type 'testDeep[key][keyof testDeep[key]]' is not assignable to type '(...args: any) => any'.
One workaround was to include
[x:string]: (...args: any) => void
in testDeep, but this led to a loss of typing assistance
Is there a way to meet the constraint requirement without making it overly generic?
Thank you!