I'm working on a larger project type definition file. I have simplified the code into an isolated example:
Module definition f.d.ts
export type myFunction = ((r: string) => Promise<any>) // async def
| ((r: string, done: (err: Error | null, b?: any) => void) => void) //callback def
export interface addFunc {
(c: string, f: myFunction): void
}
export interface FI {
addFunc: addFunc
}
export default function f(): FI
Module implementation f.js
function f () {
return {
addFunc: (c, p) => {
this[c] = p
return this
}
}
}
module.exports = f
Module utilization index.ts
import f from './f'
f().addFunc('x', (r, d) => { // Compiles as expected
d(null)
})
f().addFunc('x', async (r) => { // Error ts(7006) Parameter 'r' implicitly has an 'any' type.
return null
})
Can you please explain why this error is happening and how I could fix it? I believe the issue is in the type definition.
Please do not comment on the implementation itself; this is an extremely stripped down and isolated piece of a large API.
Thank you for the help!