Member-only story
TypeScript for Deno — A Look at Function Types
callbacks, void, undefined, unknown, and never
In the previous delivery we saw several data types that TypeScript has and we also saw the custom types that are the union of several types.
It is important to mention that you can make “object types”, that is to say, a “custom type” that is an object with a certain structure. This is great when we send information from an API for example!
Return types in functions
Just as we can type the parameters of a function, we can also type what they return, the basic example is a function that returns a number or a string, for example, a sum function.
It is necessary to remember that in general TypeScript already makes an automatic type inference, and in most cases, it is not necessary to put the type of data that a function returns but if it increases the expressiveness of the code it is better to put it.