# TypeScript

URL: https://softwaredictionary.org/terms/typescript
Category: Web Development
Last updated: 2026-09-29

In short: TypeScript is a programming language built on JavaScript that adds static types, catching many bugs before the code runs, and compiles to plain JavaScript.

## What is TypeScript?

TypeScript is JavaScript with type annotations. You can declare that a variable holds a `string`, that a function returns a `number`, or that an object must have certain properties, and the TypeScript compiler checks that your code follows those rules. Almost any valid JavaScript is also valid TypeScript, so projects can adopt it gradually.

Types exist only while you develop. The compiler, `tsc`, or a build tool strips them out and produces ordinary JavaScript that browsers and servers can run. Some runtimes, including Deno, Bun, and recent versions of Node.js, can run TypeScript files directly by removing the types on the fly.

Think of types as labels on moving boxes: they don't change what is inside, but they warn you right away if the kitchen plates are headed for the bathroom. The same checking powers editor features like autocomplete, safe renaming, and inline documentation, which is a big reason TypeScript is popular on large codebases.

A common misunderstanding is that TypeScript checks data while the program runs. It does not: after compilation the types are gone, so data from users or APIs still needs to be validated in code, often with a validation library.

## Key takeaways

- TypeScript is JavaScript plus optional static types.
- Type errors are reported before the code runs.
- Types are removed at build time, leaving plain JavaScript.
- It enables better autocomplete and refactoring in editors.
- Types do not validate external data at runtime.

## Example: Catching a mistake with types

```typescript
// Describe the shape of a user object
interface User {
  id: number;
  name: string;
}

function greet(user: User): string {
  return `Hello, ${user.name}!`;
}

greet({ id: 1, name: "Ada" }); // OK
greet({ id: 2 }); // Error: property 'name' is missing
```

## Frequently asked questions

**Is TypeScript better than JavaScript?**

Neither is better in every case. TypeScript adds safety and tooling that pay off in larger or long-lived projects, while plain JavaScript can be quicker for small scripts and prototypes.

**Do browsers run TypeScript?**

No. Browsers only run JavaScript, so TypeScript code is compiled or stripped of its types before it is sent to the browser.

**What is the difference between interface and type in TypeScript?**

Both describe the shape of data. An `interface` can be extended and merged across declarations, while a `type` alias can also express unions, tuples, and other combinations; for plain object shapes, either works.

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
