let name1: string = `Gene`;
let age: number = 37;
let sentence:string = `Hello, my name is ${ name1 }. I'll be ${age+1} years old next month`
console.log(sentence)
let list: number[] = [1,2,3];
let list2: Array<number> = [1,2,3];
let x:[string, number] = ['hello', 10];
console.log(x[1])
enum Color {Red, Green, Bule}
let c:Color = Color.Green;
console.log(c);
let t:string;
t = Color[2];
console.log(t);
let notsure: any = 4;
notsure = 'maybe a string instead';
function warnUser(): void {
alert("This is my warning message");
}
let unusable: void = undefined;
let u: undefined = undefined;
let n: null = null;
function error(message:string):never {
throw new Error(message);
}
function fail() {
return error("Something failed");
}
function infiniteLoop():never {
while(true) {
}
}
let someValue: any = "this is a string";
let strLength: number = (someValue as string).length;
const numlivesForCat = 9;
const kitty = {
name:"Aurora",
numLvives: numlivesForCat
}
kitty.name = "Rory";
kitty.numLvives--;
let [a, b, d] = [1,2,3];
console.log(a,b, d)
function test([n1, n2]:Array<any>) {
console.log(n1, n2);
}
test(["hello", 110]);
let {key,value} = {key:"K", value:"V"};
function test1({k, v}:{k:string, v:number}) {
console.log(k,v);
}
test1({k:"h1", v:100});
function printLabel(labeledObj:{label:string}) {
console.log(labeledObj.label);
}
let myobj = {size:10, label:"Size 10 Object"};
printLabel(myobj);
interface LabelledValue {
label:string;
}
function printLabel1(labelledObj:LabelledValue) {
console.log(labelledObj.label);
}
printLabel1(myobj);
interface SquareConfig {
color?:string;
width?:number;
}
function createSquare(config:SquareConfig) {
console.log(config.color);
console.log(config.width);
}
createSquare({color:"black"});
interface Point {
readonly x:number;
readonly y:number;
}
let p1:Point = {x:10, y:10};
let arr:number[] = [1,2,3,4]
let ro:ReadonlyArray<number> = arr;
arr = ro as number[];
interface SearchFunc {
(source:string, subString:string):boolean;
}
let mySearch:SearchFunc;
mySearch = function(source:string, subString:string){
return "".length > 0;
}
interface ClockInterface {
currentTime:Date;
}
class Clock implements ClockInterface {
currentTime:Date;
constructor(h:number, m:number) {
this.currentTime = new Date;
}
}