Skip to Content
Learning TypeScript 2.x - Second Edition
book

Learning TypeScript 2.x - Second Edition

by Remo H. Jansen
April 2018
Beginner content levelBeginner
536 pages
13h 21m
English
Packt Publishing
Content preview from Learning TypeScript 2.x - Second Edition

Type aliases

TypeScript allows us to declare type aliases by using the type keyword:

type PrimitiveArray = Array<string|number|boolean>; 
type MyNumber = number;  
type Callback = () => void

Type aliases are exactly the same as their original types; they are simply alternative names. Type aliases can help us to make our code more readable, but it can also lead to some problems.

If you work as part of a large team, the indiscriminate creation of aliases can lead to maintainability problems. The book Maintainable JavaScript, Nicholas C. Zakas recommends that you "avoid modifying the objects you don't own". Nicholas was talking about adding, removing, or overriding methods in objects that have not been declared by you (DOM objects, BOM objects, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering TypeScript - Fourth Edition

Mastering TypeScript - Fourth Edition

Nathan Rozentals
Learning TypeScript

Learning TypeScript

Josh Goldberg
TypeScript for Beginners

TypeScript for Beginners

Bharath Thippireddy

Publisher Resources

ISBN: 9781788391474Supplemental Content