javascript / beginner
Snippet
Defining Data Structures with Interfaces
Interfaces define the shape of your data objects. This ensures type safety and provides better developer tools like autocompletion in Angular projects.
snippet.js
javascript
1
2
3
4
5
6
export interface UserProfile {id: number;username: string;isActive: boolean;bio?: string;}
angular
Breakdown
1
interface UserProfile {
Starts the declaration of a custom data structure.
2
id: number;
Specifies that the 'id' property must always be a numeric value.
3
bio?: string;
The question mark indicates that this property is optional.