Enhancing Promises with Types
The example we're working with so far specifies the type of input to the promise, but we have to provide a type for the result in each step of the chain. That's because TypeScript doesn't know what the promise may resolve to so we have to tell it what kind of type we're getting as the result.
In other words, we're missing out on one of TypeScript's most powerful features: type inference. Type inference is the ability for TypeScript to know what the type of something should be without having to be told. A very simple example of type inference would be the following:
const hello = "hello";
No type is specified. This is because TypeScript understands that the variable hello
is being assigned a string and cannot be reassigned. If we try to pass this variable as an argument to a function that expects another type, we will get a compilation error, even though we never specified the type. Let's apply type...