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
1
function greet(name: string): string {2
return `Hello, ${name}`;3
}4
console.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
| Step / line | What happens | State after step | Output 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.