TypeScript is JavaScript with types. It compiles to plain JavaScript, so it runs everywhere JS runs. The types exist only at development time — they vanish at runtime.
The core value
TypeScript catches bugs at compile time that JavaScript only catches at runtime (if at all).
function greet(name: string): string {
return `Hello, ${name}`;
}
greet(42); // Error: Argument of type 'number' is not assignable to 'string'
Basic types
const age: number = 30;
const name: string = 'Alice';
const active: boolean = true;
const tags: string[] = ['ts', 'js'];
Interfaces
interface User {
id: number;
name: string;
email: string;
role?: 'admin' | 'editor' | 'viewer'; // optional, union type
}
function getUser(id: number): Promise<User> {
return fetch(`/api/users/${id}`).then(r => r.json());
}
Migrating an existing project
You don't have to convert everything at once. Start with allowJs: true and rename files to .ts one at a time. The compiler works progressively.
The productivity gain comes from your editor knowing the shape of every object. Autocomplete becomes accurate, refactors become safe.
Back to Blog