capypad
0 day streak
typescript / beginner
Snippet

Intersection Types

Intersection types combine multiple types into one, requiring an object to satisfy all combined structures.

snippet.ts
typescript
1
2
3
type Admin = { privileges: string[] };
type User = { name: string };
type SuperUser = Admin & User;
Breakdown
1
Admin & User
The '&' operator merges Admin and User into a single type containing properties from both.