capypad
0 day streak
typescript / beginner
Snippet

Type Aliases for Objects

Type aliases allow you to give a custom name to an object structure, making it easy to reuse the same shape across your code without using interfaces.

snippet.ts
typescript
1
2
3
4
5
6
type Point = {
x: number;
y: number;
};
 
const origin: Point = { x: 0, y: 0 };
Breakdown
1
type Point = {
Creates a new type alias named 'Point'.
2
x: number;
Defines a required numeric property 'x' for this type.