Wednesday, April 25, 2018

Angular - TypeScript Basic Syntax

Common Data Types

string
number
boolean
any - when we don't care what the type is

Using Data Types

export class MyClass {
      name: string = "Test";
}

Functions

export class MyClass {
      doSomething(name: string) : void {
      }
}

Interface

export interface IMyClass {
    name: string;
    code: string;
    doSomething(name: string) : void
}

Class Inheriting from Interface

import { IMyClass } from './myClass';
export class MyClass implements IMyClass {
    constructor(name: string, code: string) {
    }

    doSomething(name: string) : void { ... }
}

No comments: