capypad
0 day streak
typescript / beginner
Snippet

Simple Interfaces

Interfaces are used to describe the shape of an object. They act as a contract for what properties an object should have.

snippet.ts
typescript
1
2
3
4
5
6
7
8
9
interface User {
id: number;
username: string;
}
 
const user: User = {
id: 1,
username: "alex"
};
Breakdown
1
interface User {
Starts the definition of a new object structure named 'User'.
2
const user: User =
Ensures the 'user' object follows the rules defined in the User interface.