How do I declare a type that is a method of an imported module?
Suppose I have a simple file with functions:
// MyModule.ts
export const Method1 = () => {}
export const Method2 = () => {}
export const Method3 = () => {}
Now suppose I wanted to make a cool function that took one of those functions above as a parameter and then called it.
// OtherModule.ts
import * as methods from './MyModule'
//pesudocode that doesn't work
const CoolFunction = (method: typeof methods) => {
method()
}
I want the method I pass to CoolFunction to be type checked. How do I do that?
// LastModule.ts
import * as m from './MyModule'
import { CoolFunction } from './OtherModule'
// typescript should yell at me if I try to do this
const badFunction = () => void
CoolFunction(badFunction)
// but any of these should be allowed
CoolFunction(m.Method1)
CoolFunction(m.Method2)
CoolFunction(m.Method3)