Can a callable object (function) be created without utilizing Function.prototype
methods?
let callableObject = () => 'foo'
callableObject.bar = 'baz'
callableObject() // 'foo'
callableObject // {bar: 'baz'}
callableObject.call // error
An attempt was made with the following code but it did not succeed:
type ExcludeFunctionPrototypeMethods<T extends () => any> = {
[K in Exclude<keyof T, keyof Function>]: T[K]
}
function f<T extends () => any>(t: T):
ExcludeFunctionPrototypeMethods<T> {
return {} as any
}
f(() => {})() // the methods are excluded, however,
calling it results in an error message "Cannot invoke an expression whose type lacks a call signature. Type 'ExcludeFunctionPrototypeMethods<() => void>'
has no compatible call signatures."
Therefore, perhaps the question should also ask "how do I add call signatures to the type?"