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
🌐
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
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
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
Why "Operator '+' cannot be applied to types 'string | number'"?
https://github.com/microsoft/TypeScript/issues/49661 Known issue, marked as "Design limitation" Operations are evaluated according to the types of their operands, not their identities. The left-hand type is string | number, the right-hand type is string | number, and the rules for + disallow an ambiguous operation like that. Whether or not the LHS and RHS refer to the same variable (or what "same" would even mean apart from bare identifiers) isn't an input to the algorithm, nor is it clear how that could be generalized. More on reddit.com
🌐 r/typescript
14
11
November 13, 2022
🌐
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
🌐
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.
🌐
TypeScript
typescriptlang.org › docs › handbook › 2 › everyday-types.html
TypeScript: Documentation - Everyday Types
Each has a corresponding type in TypeScript. As you might expect, these are the same names you’d see if you used the JavaScript typeof operator on a value of those types: string represents string values like "Hello, world" number is for numbers like 42. JavaScript does not have a special runtime value for integers, so there’s no equivalent to int or float - everything is simply number
🌐
TypeScript
typescriptlang.org › docs › handbook › enums.html
TypeScript: Handbook - Enums
Enums allow a developer to define a set of named constants. Using enums can make it easier to document intent, or create a set of distinct cases. TypeScript provides both numeric and string-based enums.
Find elsewhere
🌐
Claude API Docs
platform.claude.com › docs › en › agent-sdk › typescript
Agent SDK reference - TypeScript - Claude API Docs
Writes a file to the local filesystem, overwriting if it exists. ... Fast file pattern matching that works with any codebase size. ... type GrepInput = { pattern: string; path?: string; glob?: string; type?: string; output_mode?: "content" | "files_with_matches" | "count"; "-i"?: boolean; "-n"?: boolean; "-B"?: number; "-A"?: number; "-C"?: number; context?: number; head_limit?: number; offset?: number; multiline?: boolean; };
🌐
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.
🌐
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.
🌐
CodeSignal
codesignal.com › learn › courses › practicing-string-operations-and-type-conversions-in-typescript › lessons › parsing-and-multiplying-numbers-in-typescript
Parsing and Multiplying Numbers in TypeScript
The next step requires iterating through the input string character by character. When we encounter a digit, we append it to our num string. If a character isn’t a digit and · isn’t empty, it means we've reached the end of a number.
🌐
Supabase
supabase.com › docs › reference › javascript › typescript-support
JavaScript: TypeScript support | Supabase Docs
3 days ago - You can use the following helper types to make the generated TypeScript types easier to use.
🌐
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

🌐
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.
🌐
DEV Community
dev.to › sanchithasr › 5-ways-to-convert-number-to-string-3fhd
5 ways to convert a number to string in JavaScript - DEV Community
August 19, 2021 - Adding empty string to the number value will convert the data to string is one of the simplest way to do the job.
🌐
Zod
zod.dev › api
Defining schemas | Zod
Zod aims to mirror TypeScript's type system one-to-one. As such, Zod provides APIs to represent the following special types: // allows any values z.any(); // inferred type: `any` z.unknown(); // inferred type: `unknown` No value will pass validation. ... // all properties are required by default const Person = z.object({ name: z.string(), age: z.number(), }); type Person = z.infer<typeof Person>; // => { name: string; age: number; }
🌐
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.