// the following is inferred to number type
let inferredType = 2;
// look for error on the following line
inferredType = \'abc\';
// the following has string type annotation
let str1: string;
// look for error on the following assignment
str1 = 123;
// the initialized value must match the annotated type
// look for error on the following assignment
let str2: string = 123;
// in the following + is string concatenation operator
let str3: string = \'some string \' + 123;
console.log( str3 );
// the following can have any type
let any;
any = 123;
console.log (any );
any = 'abc';
console.log (any );
// see error on the function parameter
function fun( num ) {
console.log( num );
}
// the following returns infered number
function fun1() {
return 500;
}
let res: string = fun1(); // error
// the following has annotated return type
function fun2() : number {
return 500;
}
let num: number = fun2();