TypeScript Types

Describe values before runtime.

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

Explanation

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

Explore the dry run
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