Having an object with a call signature and property:
type MyDescribedFunction = {
description: string
() => boolean
}
In the scenario where creating an instance is not possible in the usual manner, the following approach ensures compiler satisfaction after assigning the description property:
const functionImpl: MyDescribedFunction = () => { return true }
functionImpl.description = "Foo" // Compiler error only if this line is commented out
The objective now is to replicate the above process but have functionImpl
as a property of an object.
type MyObjType = {
name: string
fun: MyDescribedFunction
}
const myObjInstance: MyObjType = {
name: "Foo",
fun: () => { // compiler error: Property 'description' is missing in type '() => true' but required in type 'MyDescribedFunction'
return true
}
}
myObjInstance.fun.description = "Bar" // This line does not alleviate the error