Creating types for forms

We want to try to utilize TypeScript as much as possible, as it simplifies our development process and makes our app behavior more predictable. For this reason, we will create a simple data class to serve as a type for the form values.

First, create a new Angular project to follow along with the examples. Then, use the following command to create a new class:

ng g class flight

The class is generated in the app folder; replace its content with the following data class:

export class Flight {  constructor(    public fullName: string,    public from: string,    public to: string,    public type: string,    public adults: number,    public departure: Date,    public children?: number,    public infants?: number,    public arrival?: Date,  ) {}}

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.