-
Notifications
You must be signed in to change notification settings - Fork 6
Style Guide
Tim edited this page Jan 21, 2018
·
6 revisions
export interface Gizmo {
readonly description: string;
readonly id: string;
readonly name: string;
}// tslint:disable:max-classes-per-file
import { Action } from "@ngrx/store";
import { Gizmo } from "./gizmo.model";
export enum GizmoActionTypes {
//
DATABASE_DELETE_ITEM = "[Gizmo] (Database) Delete Item",
DATABASE_LISTEN_FOR_ADDED_ITEMS = "[Gizmo] (Database) Listen For Added Items"
}
export class DatabaseDeleteItem implements Action {
public readonly type = GizmoActionTypes.DATABASE_DELETE_ITEM;
constructor(public payload: { id: string; userId: string }) {}
}
export class DatabaseListenForAddedItems implements Action {
public readonly type = GizmoActionTypes.DATABASE_LISTEN_FOR_ADDED_ITEMS;
}
export type GizmoActions = DatabaseDeleteItem | DatabaseListenForAddedItems;https://angular.io/guide/styleguide#interfaces
Do name an interface using upper camel case.
Consider naming an interface without an I prefix.
Consider using a class instead of an interface for services and declarables (components, directives, and pipes).
Consider using an interface for data models.
Why? TypeScript guidelines discourage the I prefix.
Why? A class alone is less code than a class-plus-interface.
Why? A class can act as an interface (use implements instead of extends).
Why? An interface-class can be a provider lookup token in Angular dependency injection.