TypeScript Tutorials

 


1. Tuple
let x: [string, number];
x = ['rampukar', 101];
console.log(x[1]);
2. Array
let list: number[] = [1, 2, 3];
let list: Array<number> = [1, 2, 3];
3. Enum
enum Color {
      Red,
      Green,
      Blue,
    }
    let c: Color = Color.Blue;
    console.log(c); // Output: 2

enum Color {
  Red = 1,
  Green = 2,
  Blue = 4,
}
let c: Color = Color.Green;
4. Unknown
let notSure: unknown = 4;
notSure = "maybe a string instead";
notSure = false;
5. any
let looselyTyped: any = 4;
// OK, ifItExists might exist at runtime
looselyTyped.ifItExists();
// OK, toFixed exists (but the compiler doesn't check)
looselyTyped.toFixed();
6. oOur First Interface
public ioFx(labelObj: { label: string }) {
console.log(labelObj.label);
}
  
let selfObj = { size: 10, label: "Size 10 Object" };
this.ioFx(selfObj);
Share on Google Plus

About Ram Pukar

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment