I am attempting to obtain a timestamp from a Date object in Svelte and TypeScript. My goal is for the timestamp to automatically update whenever the Date object changes, so I am trying to make it reactive. Below is the code snippet I have experimented with:
let date: Date = new Date();
$: timestamp: string = date.getHours() + ':' + date.getMinutes() + ":" +
date.getSeconds(); // timestamp in format hh:mm:ss
However, TypeScript is throwing an error:
'string' only refers to a type, but is being used as a value here.
. When I remove the type declaration, everything works fine. It seems like the multiple meanings of a colon are causing confusion for the compiler, but I'm not entirely certain. Is there a way for me to achieve this while still specifying the type?