I have a variable that has type of number or string. How can I assign its value to a variable that accepts number only?
const id:Record<string, string|number> = {name:3}
let num: Record<string, number>;
num = id; //Shows error here
I know there can be javascript work arounds like writing
a conversion function, but I am learning Typescript and want to know if there are keywords or typescript specific solutions that are meant to be used in such cases, like as Record<string,number>... that can cast it, instead of type assertion
Here is a link to the code on Typescript playground
as number." - yes, that one. Just useid as number.