Custom data types

In order to group similar functionalities and have custom type checking, we are going to define classes for each entity used in our application. This will give us access to custom initialization and default values when creating entities.

User type

Our first custom data type used in the frontend Angular application will be a user. You can use an interface to define a custom type or a regular class. If you need default values or custom validation, go with a regular class definition.

Create a new file called public/src/datatypes/user.ts and add the following class:

export class User { _id: string; email: string; name: string; avatar: string; createdAt: string; constructor(_id?: string, email?: string, name?: string, createdAt?: string) ...

Get Web Application Development with MEAN now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.