Number to string typescript toString() is more appropriate. Hence you need to specify the exact type of your variable at the time of assignment. When converting strings to numbers in TypeScript, to avoid errors in your code only converts numerical strings to numbers. Dec 30, 2021 ยท TypeScript 4. However, this doesn't seem to work when I am writing the code in TypeScript. Instead it only restricts the number to the left of the decimal (the integer it seems your right, the fun thing if you change from numbers to strings you get the output i expected, i have no idea why typescript handles string and numbers differently in enums. Improve this answer. For instance, to convert a string to a number, the string must contain only numeric characters. This constructor takes a string as its only argument and returns a number value. 9, if you keyof an interface with a string index signature it returns a union of string and number. nsfcqybhzkzogupexsgztgtprtkrgsvfekofcmsimpzxfamiadtehxhnnoaljglcgmavwnlifgqfod