By 06/07/2015 9 Comments

Inferred Typing In TypeScript

Inferred Typing:

  • It is a technique/rule found in TypeScript language and called inferred typing.
  • Through an inferred technique we do not explicitly/manually specify a particular type of the variables in our TypeScript program.
  • Using an inferred rule, the TypeScript finds the variables which are used/initialized first in top level in TypeScript code, notices that what type of data is assigned first into these variables and these variables have become of that particular data type in entire TypeScript code/program.
  • For example if the TypeScript finds first a variable which holds a string type value, then that variable is became of type string and any other type of data cannot be assigned into that variable, if you assign, the TypeScript compiler will generates a compile-time error because of its inferred typing rules.


/* local variables initialization without specifying the types. TypeScript’s inferred typing rule will automatically infers the types of following variables, it identifies that the first variable is of type string and second is number type. */

var developerTool = "Visual Studio";
var pi = 3.14;

/* In following, the number type variable pi is being assigned into a string type variable developerTool. If you uncomment this code and compile, it will generate a compile-time error. */
// developerTool = pi;

// Prints the above local variables.
document.write("Developer tool: " + developerTool + " <br/>");
document.write("Value of pi: " + pi);

Next Tutorial →

← Previous Tutorial

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .