TypeScript and Python are both high-level languages with garbage collection, first-class functions and large package ecosystems. The main difference is typing: TypeScript's types are checked by the compiler before the program runs, and Python's type hints are optional annotations that the interpreter ignores. They also run on different engines and dominate different kinds of software: TypeScript the web, Python data work and scripting.
Here is a small program in TypeScript. Press Run:
Output:
162.25
[ 'Ada', 'Grace', 'Linus' ]
The same program in Python, with type hints:
from dataclasses import dataclass
@dataclass
class Order:
customer: str
amount: float
paid: bool
def total_paid(orders: list[Order]) -> float:
return sum(o.amount for o in orders if o.paid)
orders = [
Order("Ada", 120.0, True),
Order("Grace", 80.5, False),
Order("Linus", 42.25, True),
]
by_amount = [o.customer for o in sorted(orders, key=lambda o: o.amount, reverse=True)]
print(total_paid(orders))
print(by_amount)
162.25
['Ada', 'Grace', 'Linus']
The shape is close: a type for the record, a function with typed parameters, a list of values. The visible differences are syntax (braces and semicolons against indentation), interface against a @dataclass, and arrow functions with filter/reduce against a generator expression.
TypeScript vs Python at a Glance
| TypeScript | Python | |
|---|---|---|
| Typing | Static, checked at compile time; types erased at runtime | Dynamic; optional type hints, not enforced at runtime |
| Type checker | tsc, part of the language | Separate tools: mypy, pyright, and others |
| Runs on | JavaScript engines: browsers, Node.js, Deno, Bun | CPython (the standard interpreter), PyPy, and others |
| Execution | Compiled to JavaScript, then JIT-compiled by the engine | Interpreted bytecode in CPython |
| Blocks | Braces { } | Indentation |
| Numbers | number (64-bit float) and bigint | int (any size) and float |
| Concurrency | One thread per event loop, async/await; workers for parallel work | asyncio, threads, multiprocessing |
| Package manager | npm, pnpm, Yarn, Bun | pip, uv, Poetry |
| Strongest in | Web front ends, Node.js back ends, full-stack apps | Data science, machine learning, scripting, automation, back ends |
Syntax Side by Side
If you know Python's type hints, most TypeScript annotations have a direct counterpart:
| Python | TypeScript |
|---|---|
count: int = 0 | let count: number = 0; |
def add(a: int, b: int) -> int: | function add(a: number, b: number): number { |
lambda x: x * 2 | (x) => x * 2 |
list[str] | string[] |
dict[str, int] | Record<string, number> or Map<string, number> |
tuple[int, str] | [number, string] |
str | None | string | null or string | undefined |
Literal["asc", "desc"] | "asc" | "desc" |
Callable[[int], str] | (n: number) => string |
TypedDict | interface or type |
@dataclass | a class, or an interface for plain data |
Any | any |
None, True, False | null (or undefined), true, false |
and, or, not | &&, ||, ! |
f"Hello {name}" | `Hello ${name}` |
Static Types vs Type Hints
Both languages let you write the same annotation, a: number or a: int. What happens next is different.
In TypeScript, the compiler checks every call before anything runs. A wrong argument stops the build:
index.ts(7,17): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
In Python, the hints are metadata. The interpreter runs the call and returns a string:
def add(a: int, b: int) -> int:
return a + b
print(add(2, 3)) # 5
print(add("2", "3")) # 23, the hints are not enforced
Checking is a separate step with a tool like mypy:
$ mypy hints.py
hints.py:6: error: Argument 1 to "add" has incompatible type "str"; expected "int" [arg-type]
hints.py:6: error: Argument 2 to "add" has incompatible type "str"; expected "int" [arg-type]
Found 2 errors in 1 file (checked 1 source file)
So Python typing is gradual by design: unannotated code is simply not checked, and you add hints where they help. TypeScript can be loose too (any switches checking off for a value), but with strict on, which is the default, an unannotated parameter is an error rather than a free pass.
One thing both share: neither checks types while the program runs. TypeScript erases its types, and Python ignores its hints. Data that arrives at runtime, such as JSON from an API, needs validation in both languages (libraries such as Zod in TypeScript and Pydantic in Python do this from a schema).
Numbers Behave Differently
TypeScript has JavaScript's numbers: number is a 64-bit floating-point value for both integers and fractions, and bigint is a separate type for large integers. Python's int grows to any size on its own.
Output:
0.30000000000000004
9007199254740992
3.5 3
1267650600228229401496703205376n
Python prints 9007199254740993 for 2**53 + 1, since its integers are exact at any size, and it has a dedicated integer division operator, 7 // 2, which gives 3. There is no int type in TypeScript; an integer is a number that happens to have no fraction.
Runtime and Performance
TypeScript runs as JavaScript. V8 (in Chrome and Node.js), JavaScriptCore (in Safari and Bun) and SpiderMonkey (in Firefox) compile hot code to machine code while it runs, so tight loops in TypeScript are usually much faster than the same loops in CPython, which executes bytecode.
That gap matters less than it sounds for many programs:
- Python's numeric and machine learning libraries (NumPy, pandas, PyTorch) do their heavy work in compiled C, C++ or CUDA code, so a Python program that calls them is not running its inner loops in Python.
- Web servers in either language spend much of their time waiting on databases and networks.
Both languages use one main thread for most code. TypeScript on Node.js handles concurrency with an event loop and async/await, and uses worker threads for parallel CPU work. Python has asyncio for the same style of concurrency, plus threads and processes.
Ecosystems and Use Cases
TypeScript is the default for:
- Web front ends: React, Angular, Vue and Svelte all support it, and it compiles to the JavaScript that browsers run.
- Server code on Node.js, Deno and Bun: APIs with Express, Fastify, NestJS or Hono.
- Full-stack apps where the server and the browser share type definitions, such as Next.js projects.
- Tooling, command line tools and desktop apps with Electron.
Python is the default for:
- Data analysis and visualization (pandas, NumPy, Matplotlib, Jupyter notebooks).
- Machine learning and AI (PyTorch, scikit-learn, and most model training code).
- Scripting and automation: file processing, system administration, glue code.
- Web back ends with Django, Flask or FastAPI.
- Scientific computing and teaching.
Back-end web development is where they overlap most. Teams often pick by what the rest of the stack uses: TypeScript to share code with a TypeScript front end, Python to sit next to data and ML code.
Which One Should You Learn?
- Building for the web? Learn JavaScript, then TypeScript. Everything that runs in a browser is JavaScript in the end, and TypeScript is how most professional front-end code is written.
- Working with data, AI or automation? Learn Python. Its libraries in those areas have no real equivalent in the JavaScript world.
- First language, no fixed goal? Python has less syntax to learn before you can write useful programs. TypeScript adds a type system on top of JavaScript, which is extra to learn at first and pays off as programs grow.
Many developers use both: Python for data and scripts, TypeScript for the product's web code. If you already know Python's type hints, TypeScript's annotations will look familiar; the new parts are that the compiler enforces them by default and that the runtime underneath is JavaScript.
Frequently Asked Questions
Is TypeScript better than Python?
Neither is better in general; they lead in different areas. TypeScript is the standard choice for web front ends and common for Node.js servers, and its type checking is built into the normal workflow. Python leads in data science, machine learning, scripting and automation, and has type hints you can check with tools such as mypy or pyright.
Is TypeScript faster than Python?
For CPU-bound code written in the language itself, usually yes: TypeScript compiles to JavaScript, which engines like V8 compile to machine code at runtime, while the standard Python interpreter, CPython, runs bytecode. Python programs that spend their time in libraries written in C (NumPy, pandas, PyTorch) are not limited by that, and for network-bound servers the difference is often small.
Does Python have static typing like TypeScript?
Python has optional type hints (def add(a: int, b: int) -> int), but the interpreter does not enforce them: add("2", "3") runs and returns "23". A separate checker such as mypy or pyright reports the mismatch. In TypeScript, checking is the compiler's main job, and projects are normally set up so code with type errors does not build.
Should I learn TypeScript or Python first?
Pick by what you want to build. For websites and web apps, learn JavaScript and then TypeScript, since browsers only run JavaScript. For data analysis, machine learning, automation or a first language with very little syntax, start with Python. The core ideas (variables, functions, loops, objects) carry over either way.