RUN

Catch a type error in TypeScript

See how TypeScript stops a bug before the code runs. Press Run to try it, then change the code and run it again.

main.ts

function double(n: number): number {
  return n * 2;
}

// Fix the line below: the age arrives as text.
const age = '21';
console.log(double(age));
Output

Press Run to see the output.

More TypeScript examples

Open the full TypeScript online compiler →