Exactly like in JavaScript, you can use the parseInt or parseFloat functions, or simply use the unary + operator:

var x = "32";
var y: number = +x;

All of the mentioned techniques will have correct typing and will correctly parse simple decimal integer strings like "123", but will behave differently for various other, possibly expected, cases (like "123.45") and corner cases (like null).

Table taken from this answer

Answer from Ryan Cavanaugh on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › how-to-convert-string-to-number-in-typescript
How to Convert String to Number in TypeScript? - GeeksforGeeks
July 23, 2025 - Example: The following code demonstrates converting a string to a number by using the '+' unary operator. ... The Number() method in TypeScript converts a string to a number by explicitly invoking the Number constructor.
Discussions

Easiest Ways to Convert Strings to Numbers in TypeScript [Pie Chart]
I’m sorry, is this LinkedIn? More on reddit.com
🌐 r/angular
6
0
August 21, 2024
How to convert a string to a number in TypeScript? - TestMu AI Community
How to Convert a String to a Number in TypeScript? Given a string representation of a number, how can I convert it to number type in TypeScript? var numberString: string = "1234"; var numberValue: number = /* what should I do with numberString? */; How do I achieve this typescript string to number ... More on community.testmu.ai
🌐 community.testmu.ai
0
July 31, 2024
Is there a way to avoid explicitly casting object keys to numbers?
You could use a Map – then your keys are really numbers: type FrequencyMap = Map; const getFreq = (arr: number[]) => { const freq: FrequencyMap = new Map(); for (const x of arr) { const prevValue = (freq.get(x) ?? 0); freq.set(x, prevValue + 1); } return freq; }; const myFunc = (nums: number[]): number[] => { const keys = Array.from(getFreq(nums).keys()); return keys.reduce(/*···*/); }; More on reddit.com
🌐 r/typescript
16
27
November 27, 2022
How to define a function that has any number of string or number parameters
Drop the generics, it's cleaner that way. const fn = (...args: Array) => {} https://www.typescriptlang.org/play?#code/MYewdgzgLgBAZmGBeGAKAdJghgJwOYQBcMAgjjlgJ4A8YArgLYBGApjjAD4zQ4CWYeAHwBKZIJgBvAL4AoGQHp5MEAGsZCVAEZh6sKgBE+nRv09+efQBoYpqHwFHdBsw+sAWa7fsWdCpWBBYVSdjPTgsABsIFlDnO3MrGABWa3ComKA More on reddit.com
🌐 r/typescript
14
6
November 17, 2022
🌐
DEV Community
dev.to › smpnjn › how-to-convert-a-string-to-a-number-in-typescript-4ei4
How to convert a String to a Number in TypeScript - DEV Community
June 19, 2022 - If we're using integers, the easiest way to convert a string into a number is to simply use the unary (+) operator.
🌐
Medium
medium.com › @bobjunior542 › mastering-typescript-convert-strings-to-numbers-now-ea30bf171e43
Mastering TypeScript: Convert Strings to Numbers Now | by Bob Junior | Medium
April 25, 2023 - In this article, we’ll take a look at how to convert a string to a number in TypeScript and explore some common scenarios where this is necessary.
🌐
Execute Program
executeprogram.com › courses › typescript-basics › articles › how-to-convert-a-string-to-a-number-in-typescript
How to convert a string to a number in TypeScript
Learn programming languages like TypeScript, Python, JavaScript, SQL, and regular expressions. Interactive with real code examples.
🌐
SPGuides
spguides.com › convert-string-to-number-in-typescript
Convert String to Number in TypeScript [With Examples]
April 3, 2025 - In this tutorial, I will explain how to convert a string to a number in TypeScript using different approaches with examples.
🌐
Reddit
reddit.com › r/angular › easiest ways to convert strings to numbers in typescript [pie chart]
r/angular on Reddit: Easiest Ways to Convert Strings to Numbers in TypeScript [Pie Chart]
August 21, 2024 -

Converting strings to numbers in TypeScript is easy! This pie chart breaks down the most popular methods: Unary Operator, Number(), and parseInt/parseFloat.

Which one do you prefer?

TypeScript #Programming #WebDev

Find elsewhere
🌐
Codemia
codemia.io › knowledge-hub › path › how_to_convert_a_string_to_number_in_typescript
How to convert a string to number in TypeScript?
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
🌐
Geekflare
geekflare.com › development › typescript string to number: 5 ways for easy conversion
TypeScript String to Number: 5 Ways for Easy Conversion
December 28, 2024 - Using the unary plus (+) operator is a good way to convert strings to numbers as it is fast and does not do any additional operations on its operands. Just like in JavaScript, Typescript does not distinguish between integers and decimal numbers also known as floating point numbers.
🌐
Bobby Hadz
bobbyhadz.com › blog › typescript-convert-number-to-string
Convert a Number to a String in TypeScript | bobbyhadz
February 28, 2024 - Use the String() constructor to convert a number to a string in TypeScript.
🌐
Patrick Desjardins
patrickdesjardins.com › blog › typescript-cast-of-string-to-number
Patrick Desjardins Blog - TypeScript cast of string to number
This means that you can either use the parseInt function or to simply add a plus sign in from of your string. var myInt1 = +"123"; var myInt2 = +myStringVariable; var myInt3 = parseInt("123", 10); var myInt4 = Number("123")
🌐
DevGenius
blog.devgenius.io › converting-a-string-to-a-number-in-typescript-a-comprehensive-guide-cdc74ac6de0f
Converting a String to a Number in TypeScript: A Comprehensive Guide | by Chintanonweb | Dev Genius
February 23, 2024 - Converting a string to a number in TypeScript involves various techniques, from basic methods like parseInt and parseFloat to more advanced approaches using the unary plus operator and the Number constructor.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › typescript tutorial › typescript number to string
TypeScript number to string | Learn the Examples and Primitive Types
April 5, 2023 - One way is to append the empty ... type as a string and to append an empty string to the number typescript provides “+” operator for appending....
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Andrew Hansen
arahansen.com › how-to-convert-a-string-to-a-number-in-typescript
How to convert a string to a number in TypeScript
January 17, 2022 - To coerce a string into a number, we can wrap our value in one of several functions: parseInt, parseFloat, or Number (this stackoverflow answer has a great breakdown of the differences).
🌐
Tektutorialshub
tektutorialshub.com › home › typescript › convert string to number in typescript
Convert String to Number in Typescript - Tektutorialshub
March 15, 2023 - There are several ways you can convert Typescript String to Number. The best way is to make use of the unary plus + operator or the Number global function. You can make use of the parseint or parsefloat functions.
🌐
Codedamn
codedamn.com › news › typescript
How to convert string to number in TypeScript?
November 16, 2022 - “How to convert string to number in TypeScript?” article uses three methods namely using the number, parseInt, and unary(+) for conversion.
🌐
Fjolt
fjolt.com › article › typescript-convert-string-to-number
How to convert a String to a Number in TypeScript
June 18, 2022 - let someString:string = "4245.1234" let myNumber:number = parseFloat(someString); // Returns 4246.1234 console.log(myNumber + 1); We can also use the Number function to convert number-like strings into numbers.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › typescript tutorial › typescript string to number
TypeScript string to number | Quick Glance on TypeScript string to number
April 6, 2023 - A string in TypeScript can be converted to a number using an operator called unary plus (+) operator or using the functions called parseInt function or parseFloat function, or Number function where the unary plus operator converts the numbers ...
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-string-to-number-in-typescript
How to convert string to number in TypeScript?
February 21, 2023 - This method converts a number object into a human readable string representing the number using the locale of the environment. Returns a human readable string representing the number using the locale of the environment.
🌐
TestMu AI Community
community.testmu.ai › ask a question
How to convert a string to a number in TypeScript? - TestMu AI Community
July 31, 2024 - How to Convert a String to a Number in TypeScript? Given a string representation of a number, how can I convert it to number type in TypeScript? var numberString: string = "1234"; var numberValue: number = /* what shoul…