By 06/07/2015 18 Comments

The “any” Type In TypeScript

The “any” Type:

  • TypeScript has a data type called “any” and can be declared using a keyword “any”.
  • As we know TypeScript is a strong typed language therefore TypeScript compiler strictly checks the type of data. In TypeScript we define arrays, variables, objects, functions of a specific type such as string, boolean, number etc. and we cannot assign number into string, string into number etc.
  • TypeScript’s “any” data type allows us to create and assigns mix/different data types to a variables without worrying a specific type. Such as we declare a variable which can hold the different/mix data types at same time, such is string, number, boolean etc.
  • In TypeScript the “any” data type can be used with data variables, arrays, objects, functions etc.
  • If we do not supply a specific data type to TypeScript’s members then that uses “any” type by default.

Example:

/* Following is an array creation which has “any” its data type. Notice this array contains different/mix data types at a time, it contains string, boolean and number type. */
var mixProducts: any = ["Visual studio", "Ms.Office", "TypeScript", 2054 , true];

// Loop through each array element and print it.
for (var index = 0; index < 5; index++)
    document.write(mixProducts[index]+ " <br/>");





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 .