It's not overloaded; instead, it is a function that also includes a property called promise
. You can create such an object using Object.assign
:
let fn: SearchResultSetEachFunction = Object.assign(function (callback: (result: Result) => boolean): void {
}, {
promise(callback: (result: Result) => boolean): Promise<boolean> {
return Promise.resolve(false)
}
})
Playground Link
In newer versions of TypeScript, you can use a function declaration and directly assign the promise
member in the same scope as the declaration for TypeScript to recognize it as a new member:
function mockSearchResultSetEachFunction(callback: (result: Result) => boolean): void {
}
mockSearchResultSetEachFunction.promise = function (callback: (result: Result) => boolean): Promise<boolean> {
return Promise.resolve(false)
}
let fn: SearchResultSetEachFunction = mockSearchResultSetEachFunction
Playground Link