Promise Fundamentals using TypeScript

Share this video with your friends

Send Tweet

Learn the fundamentals of creating, resolving and rejecting promises using TypeScript. We also cover the fundamentals of a .then chain.

We will see how the Promise constructor takes an executor callback which will be called at runtime with two arguments (resolve and reject).

hjmccain
~ 6 years ago

Hi! Thanks for the tutorial. I installed Typecript globally, but when I try to run the .ts file in this tutorial, I get the following error: "error TS2693: 'Promise' only refers to a type, but is being used as a value here." What am I missing? I notice you have a tsconfig file — do I need that?

Basarat Ali Syedinstructor
~ 6 years ago

What am I missing? I notice you have a tsconfig file — do I need that?

Yes. Specifically the lib option : https://basarat.gitbooks.io/typescript/content/docs/types/lib.d.ts.html

Brendan Whiting
~ 6 years ago

Is there any difference between throwing an error inside a promise and reject the promise?

Basarat Ali Syedinstructor
~ 6 years ago

@brendan inside a promise chain : no. there is no difference.

Brendan Whiting
~ 6 years ago

Cool thx