I have a vision of creating a message feature that can be invoked directly with overloading capabilities. I also wish to incorporate other function calls within this message feature, such as message.confirm(). Achieving this in TypeScript seems challenging when it comes to writing type descriptions and implementing them simultaneously.
My attempts at defining a class showed that the use of the new keyword is necessary for calling it. Trying to define a function directly also proved insufficient in meeting the required function properties. This process requires careful steps to fully accomplish.
As an example, consider the following class definition which prompts the need to use new for invocation:
class message {
message(msg: string): any
message(msg: string, type: string): any
message(msg: string, type?: string){
}
static confirm(){
}
}
message("123")
Another hurdle I face is with the following definition:
type Message = {
message(msg: string): any
message(msg: string, type: string): any
confirm(): any
}
const message: Message = function message (msg: string, type?: string)
{
}
message.confirm = function(){}
My ultimate question remains - How can I effectively define and implement the message function?