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 promise: Promise<string> = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("This is my code");
},1000)
});
promise.then(data => {
data.split(' ');
});
Comments
Post a Comment