Local types

The TypeScript type system allows us to declare types (such as type aliases, classes, and interfaces) within the declaration of functions and methods. In the early releases of TypeScript, this was not allowed:

interface Person {    name: string;    age: number;}function makePerson(name: string, age: number): Person {    // Local type    class Person implements Person {        constructor(            public name: string,            public age: number        ) {}    }    return new Person(name, age);}let user = makePerson("Remo", 28);

Get Learning TypeScript 2.x - Second Edition 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.