Getting Started with TypeScript: Includes Introduction to Angular by Huber Thomas Claudius

Getting Started with TypeScript: Includes Introduction to Angular by Huber Thomas Claudius

Author:Huber, Thomas Claudius [Huber, Thomas Claudius]
Language: eng
Format: epub
Publisher: UNKNOWN
Published: 2017-02-03T16:00:00+00:00


id: number;

}

Listing 7.12: 07\05_genericConstraints\main.ts

With the interface defined, you can use it on the generic type parameter with the extends -keyword like in listing 7.13.

class GenericRepo<T extends IHaveId > {

private _items = new Array<T>();

getById(id: number) {

return this._items.filter(item => item.id === id)[0];

}

...

}

Listing 7.13: 07\05_genericConstraints\main.ts

Now the GenericRepo<T> -class only works with types that have an id -property, like for example the Friend -class of listing 7.14.

class Friend {



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.