February 2019
Beginner
694 pages
18h 4m
English
So far, we have defined all of our promise objects as Promise<void>. The void in this case indicates that our promises will not return any values. If we use Promise<string>, this indicates that our promises will return string values. Let's take a look at how to return values from promises, as follows:
function delayedPromiseWithParam() : Promise<string> {
return new Promise<string>(
(
resolve: (str: string) => void,
reject: (str:string ) => void
) => {
function afterWait() {
resolve("resolved_within_promise");
}
setTimeout( afterWait , 2000 );
}
);
}
Here, we have a function named delayedPromiseWithParam that constructs and returns our promise object as usual. Note, however, that the definition of both the ...
Read now
Unlock full access