greg-murray-volusion / understanding-typescript

O'Reilly course Understanding Typescript exercises

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Understanding Typescript

From O'Reilly "Understanding Typescript" video course

Chapter 2: Using Types for better Code

Cameron had a great question, why does the following code compile when the output method signature on the object does not match the interface?

interface Complex {
    data: number[];
    output: (all: boolean) => number[];
}

const complex: Complex = {
    data: [100, 3.99, 10],
    output(): number[] {
        return this.data;
    },
};

See Microsoft Typescript wiki for their explanation.

Chapter 3: Understanding the TypeScript Compiler

{
  "noImplicitAny": true,
  "noUnusedParameters": true,
  "sourceMap": true,
  "strictNullChecks": true
}
  • Unused parameters can be prefixed with _ to avoid error.
  • strict null checks disallow reassigning null to a variable.

Chapter 4: TypeScript and ES6

class Person {
  name: string; // default is public
  private ssn: number;
  protected age: number;

  // username will be created as a public field
  constructor(name: string, public username: string) {
    this.name = name;
  }
}

Other resources

Typescript handbook

Typescript Deep Dive

If you have an O’Reilly account, I recommend the author Remo H. Jansen.

Learning Typescript 2x by Remo Jansen

About

O'Reilly course Understanding Typescript exercises

License:MIT License


Languages

Language:TypeScript 100.0%