SOLVED: Error when using variables for text in node.status function

Sorry if this is a total noob question. I am quite inexperienced in Javascript.

I’ve made a function to “replicate” Philips Hue’s built-in “Dynamic scene” where the lights changes scenes automatically at a given time with a slow transition. The function works somewhat fine but for debugging purposes I need to show the next timeswitch and found out that it could be done via node.status() (so I don’t need to have debugging nodes open all the time).

However I get a strange error message whenever i put in a variable in the "text" argument of node.status():

No overload matches this call.
Overload 1 of 2, ‘(status: NodeStatus): any’, gave the following error.
Type ‘() => string’ is not assignable to type ‘string | number | boolean’.
Overload 2 of 2, ‘(status: string | number | boolean): any’, gave the following error.
Argument of type ‘{ fill: string; shape: string; text: () => string; }’ is not assignable to parameter of type ‘string | number | boolean’.(2769)

Here is the code:

let nextTimeSwitch;
nextTimeSwitch = new Date(dtSubstring + nextEndTime);
node.status({fill:"green",shape:"dot",text: nextTimeSwitch.toTimeString});

There’s a lot more in this function but I boiled it down to where the issue is. The nextTimeSwitch variable is made up of two substrings but this is not the issue since it is returned to msg.delay which is later used in a delay node, and this works just fine.

How do I fix this issue?

Javascript is un-typed, and overloading is the practice of allowing multiple data types where one specific type is required.

The node status text field requires a string. However JS is forgiving and accepts numbers and boolean, and the interpretor calls a function to perform the appropriate conversion.

That said, not every eventually is catered for. You appear to be creating a JS Date object, which is a specific type in JS, and needs to be converted to a string at some point.

totimestring is indeed a method of the Date object that returns a stringified time, but I believe that the correct format is to call as a function.

Perhaps toTimeString() will work?

https://www.w3schools.com/jsref/jsref_totimestring.asp

The linked website above is my goto reference for Javascript. There is just too much to remember

That absolutely did the trick! Thank you so much for your help.