Showing posts with label Typescript. Show all posts
Showing posts with label Typescript. Show all posts

Wednesday, June 27, 2018

Remove duplicate record from Javascript Array in ES6

There are many way's to implement it but ES6 make it so cool.
Let see how: 

let arr = [1, 2, 2, 3, 4];
let distinctArray = new Set(arr);

Monday, June 25, 2018

Tuple data type in Typescript

// Declare a tuple type
let tuple: [string, number, boolean ];
// Initialize it
tuple = ["hello", 10, false]; // OK
// Initialize it incorrectly
tuple = [10, "hello", false]; // Error

console.log(tuple[0]);  // hello

console.log(tuple[1]);  // 10

Friday, June 22, 2018

Use returned values from super calls as ‘this’ in typescript

class Base{ x: number; constructor() { // return a new object other than `this` return { x: 1, }; } } class Derived extends Base { constructor() { super(); }

public ShowValue(){
this.x;
} }

Thursday, June 21, 2018

Call parent class constructor in Typescript


export class BaseClass{
    constructor()
{
console.log('Base Constructor');
}
}

export class ChildClass extends BaseClass
    constructor() {
        super();
console.log('Child Constructor');
    }
}


Result:

Base Constructor
Child Constructor

By using the super keyword we can call base class constructor.
In Child class constructor super should be the very first statement.
If you want to wait till for some operation will be done then child class
constructor call. Then we can use super.

Monday, August 8, 2016

Advantage or Benefits of TypeScript


  1. Static type checking
  2. Similar to language like C#, JAVA, Scala
  3. Support ES6
  4. It offers support for the latest ECMAScript for future proposals.
  5. It support almost all the popular Javascript libraries like JQuery, Angular JS, Angular 2 etc.
  6. Typescript is the superset of Javascript.
  7. Its support typings that is highly productive.
  8. With the help of type checking we can static verify our code.
  9. Provide better intellisence
  10. Support class, interface and modules