TypeScript · Course navigation

TypeScript Types

Describe values before runtime.

On this page

The concept

Type annotations let the compiler check how values are used. TypeScript erases annotations when generating JavaScript.

Code example

TypeScript
function greet(name: string): string {
  return `Hello, ${name}`;
}
console.log(greet("Ada"));
Output
Hello, Ada

Follow the code

Open the walkthrough to inspect the example one step at a time.

Show guided walkthrough
Guided walkthroughReady
1function greet(name: string): string {
2 return `Hello, ${name}`;
3}
4console.log(greet("Ada"));

Follow the example

Start to inspect the source, values, and output. These prepared steps explain the published sample; grouped loop steps describe multiple iterations.

View the complete dry-run table
Prepared trace of the published program. Some rows group repeated iterations.
Step / lineWhat happensState after stepOutput so far
The type annotations are checked and removed during compilation.—
—
Call greet with Ada.name = "Ada"
—
Build and return the greeting string.return = "Hello, Ada"
—
Write the result.return = "Hello, Ada"
Hello, Ada

Behind the scenes

How TypeScript processes this code

TypeScript checks types and emits JavaScript. Type annotations are removed before execution.