TypeScript Generics

Generics:

Generic is a type which connected to other type, where we don't know what type of data it will return
//Generics
const names :Array<string> = []; //which is similar to string array as const names: string[]

Promises:

Anothor example is promise method, which allows to two arguments in a method and return string type array.
Promise is a built in generic type in typescript

const promise = new Promise() // which is a constructor function.

Syntax example
const promisePromise<string> = new Promise((resolvereject=> {
    setTimeout(() => {
        resolve("This is my code");
    },1000)     
});

promise.then(data => {
    data.split(' ');
});


Comments

Popular posts from this blog

Powerapps overcome 2000 item limit from any datasource

PowerApps multiselect cascading dropdown and save an item to SharePoint List

Multi select cascading dropdown in Power Apps