# Typescript Fundamentals Cheatsheet
Table of Contents
TypeScript is a strongly-typed superset of JavaScript that compiles to plain JavaScript. This cheatsheet covers the most important syntax and features you need to get started.
Basic Types
let isDone: boolean = falselet age: number = 42let firstName: string = 'Alice'let list: number[] = [1, 2, 3]let tuple: [string, number] = ['hello', 10]
Any and Unknown
let notSure: any = 4notSure = 'maybe a string'
let value: unknown = 'Hello'if (typeof value === 'string') { console.log(value.toUpperCase())}
Functions
function add(x: number, y: number): number { return x + y}
const greet = (name: string): void => { console.log(`Hello, ${name}`)}
Interfaces
interface User { name: string age?: number // optional}
const user: User = { name: 'Bob' }
Type Aliases
type ID = string | numberlet userId: ID = 123
Enums
enum Direction { Up, Down, Left, Right,}
let dir: Direction = Direction.Up
Generics
function identity<T>(arg: T): T { return arg}
let output = identity<string>('Hello')
Classes
class Person { constructor( public name: string, private age: number, ) {}
greet() { console.log(`Hi, I'm ${this.name}`) }}
const alice = new Person('Alice', 30)alice.greet()
Modules
export function add(a: number, b: number): number { return a + b}
// file: app.tsimport { add } from './math'console.log(add(2, 3))
Type Assertions
let someValue: unknown = 'this is a string'let strLength: number = (someValue as string).length
Utility Types
Partial<T>
— all properties optionalReadonly<T>
— all properties read-onlyPick<T, K>
— select specific propertiesOmit<T, K>
— remove specific properties
Example:
interface Todo { title: string description: string}
type TodoPreview = Pick<Todo, 'title'>
Compilation
tsc file.ts
Compile and watch for changes:
tsc -w
Final Thoughts
This cheatsheet gives you the essentials for working productively with TypeScript. Master these fundamentals before moving on to advanced typing and complex generics.