Set up TypeScript

7.0.2

TypeScript checks types before a program runs. Type annotations do not validate incoming data at runtime.

On this page

Install and check a project

Install TypeScript as a development dependency so the team can share a compiler version. Start with a tsconfig.json. Run tsc with --noEmit when you want diagnostics without build files.

npm install --save-dev typescript@7.0.2
npx tsc --init
npx tsc --noEmit

Strict checking and inference

Use strict checking for new projects. TypeScript can infer types from values and return expressions. Add annotations at boundaries such as function parameters or exported contracts.

export function total(price: number, units: number) {
  return price * units;
}

const amount = total(3, 2); // inferred as number

Official references