TypeScript Important Topics Summary
A concise guide covering essential TypeScript topics for front-end and full-stack projects.
1. Type Basics
-
Primitive types:
string,number,boolean,null,undefined,bigint,symbol -
Any vs unknown vs never
any= opt-out of type checking (use sparingly)unknown= safer, must check type before usingnever= function never returns or always throws
-
Union & Intersection types:
string | number,TypeA & TypeB -
Literal types:
'success' | 'error' -
Type aliases:
type ID = string | number
2. Arrays & Tuples
- Typed arrays:
number[]orArray<number> - Tuples:
[string, number]with fixed length and types - Optional elements & rest in tuples:
[string, number?],[string, ...number[]]
3. Objects & Interfaces
-
Interfaces vs Types:
interfacesupports declaration mergingtypeis more flexible (unions, intersections)
-
Optional and readonly properties:
prop?: string,readonly id: number -
Index signatures:
{ [key: string]: number } -
Extending interfaces:
interface A extends B {}
4. Functions
- Typed parameters & return types:
(x: number) => string - Optional & default parameters:
(x: number, y?: number) - Rest parameters:
(...args: number[]) - Function overloads
5. Classes & OOP
- Class properties with types:
class User { name: string } - Constructor shorthand:
constructor(public name: string) {} - Access modifiers:
public,private,protected,readonly - Inheritance &
super() - Abstract classes and methods
- Implements interfaces
6. Generics
- Generic functions:
function identity<T>(arg: T): T - Generic constraints:
T extends SomeType - Generic classes and interfaces
7. Enums
- Numeric enums:
enum Direction { Up, Down } - String enums:
enum Status { Success = "success" } - Const enums for optimization
8. Type Guards & Type Narrowing
typeofandinstanceof- User-defined type guards:
function isString(x: unknown): x is string {
return typeof x === 'string';
}
9. Advanced Types
- Mapped types:
type Readonly<T> = { readonly [K in keyof T]: T[K] } - Conditional types:
T extends U ? X : Y - Utility types:
Partial<T>,Required<T>,Pick<T, K>,Omit<T, K>
10. Modules & Imports
export/importsyntax- Default vs named exports
- Re-exporting:
export * from './file'
11. Type Assertions & Non-null
- Type assertion:
value as string - Non-null assertion:
value! - Optional chaining:
obj?.prop - Nullish coalescing:
??
12. Working with DOM / Libraries
- Typings for DOM APIs:
HTMLElement,Event,MouseEvent - Third-party types:
@types/lodash,@types/react
13. Configuration & Compiler Options
tsconfig.jsonbasics:strict,noImplicitAny,target,modulestrictmode catches most mistakes- Understanding
esModuleInteropandallowJs
Pro tip: Focus first on types, generics, OOP, and utility types. Then learn modules and DOM interaction for practical project work.