Skip to content

Tag: promise

Why does TypeScript use “Like” types?

Why does TypeScript have a type and then a “like type”? An example of this is Promise<T> and PromiseLike<T>. What are the differences between these two types? When should I use them? In this case why not just have one Promise type? Answer If you look at the definition files (let’…

fetch response.text() returns pending promise

I test the fetch API with jsonplaceholder URL, but my function returns “Promise State: Pending”, and I don’t understand why : I think the problem is because of asynchronous/synchronous methods? Answer I think the problem become asynchrone/synchrone method ? Yes. You’ve (mostly) correct…

Rethrowing error in promise catch

I found the following code in a tutorial: I’m a bit confused: does the catch call accomplish anything? It seems to me that it doesn’t have any effect, since it simply throws the same error that was caught. I base this on how a regular try/catch works. Answer There is no point to a naked catch and …