capypad
0 day streak
typescript / beginner
Snippet

Inline Object Type Annotations

You can define the expected structure of an object directly during variable declaration. This ensures the object has exactly the required properties and types.

snippet.ts
typescript
1
2
3
4
let point: { x: number; y: number } = {
x: 10,
y: 20
};
Breakdown
1
{ x: number; y: number }
The type definition requiring the object to have numeric 'x' and 'y' properties.
2
x: 10, y: 20
The actual values assigned to the object, which must match the defined type exactly.