Basics

Challenges

Classes

Cookies

Debugging

Events

External Files

Flow Control

Forms

Functions

Html Elements

Installation

Interfaces

Keywords

Modules

Namespaces

Operators

Reference Files

String

Types

TypeScript - Type Annotations

In TypeScript, you should use Type Annotations to declare your Types. Although these works:


// these are inferred. It seems that these should be of type <T>.
var age = 50;
var anything;
var num1;

It really should be handled like this:


let age : number = 50;
let anything : any;
let num1 : number;

It really should be handled like this:


// this will work although you shouldn’t do this
// str1 will be inferred into a string.
var num1 : number = 100;
var str1 = num1 + " some string"; // will show as ‘100 some string’