I am in the process of developing a telegram bot
I have the need to save all my messages as constants
My message schema is structured as follows:
type MessagesSchema = {
[K in keyof typeof MessagesEnum]: string
}
Here is an example implementation:
const Messages: MessagesSchema = {
SOME_KEYS_FROM_ENUM = '123',
...
FUNCTIONAL_VALUE: (a: number) => `The number is ${a}`
}
I am facing a challenge where I am unable to store functions as values in this constant.
How can I modify the schema to allow this functionality?
I have attempted to update it as follows:
type MessagesSchema = {
[K in keyof typeof MessagesEnum]: string | ((...params: any) => string)
}
However, this approach requires me to check if the value in the object is a function each time I use it:
if(typeof Messages.FUNCTIONAL_VALUE === 'function'){
...
}