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 inference

TypeScript tries to find the types of the variables and objects in our application using what is known as type inference. When we declare a variable, TypeScript will try to observe the value assigned to the variables in the application to identify its type. Let's examine some examples:

let myVariable1 = 3;

The type of the variable myVariable1 is inferred as a number.

let myVariable2 = "Hello";

The type of the variable myVariable2 is inferred as a string.

let myVariable3 = {  name: "Remo",  surname: "Jansen",  age: 29};

The type of the variable myVariable3 is inferred as the following type:

{ name: string; surname: string; age: number; }

The type any is assigned in the cases in which TypeScript is not able to identify the type ...

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