In TypeScript, return type specifies the type of the value that a function returns. A function return type can be defined using a type annotation in the function signature.
Here's an example of declaring a function with a return type:
index.ts70 chars4 linesIn the above example, the return type is defined as number using a type annotation after the function parameter list.
If a function does not have a return type annotation, TypeScript will infer the return type as any.
index.ts62 chars4 linesIn the above example, TypeScript infers the return type as any.
It is always recommended to specify return type in function signature to avoid any runtime errors.
gistlibby LogSnag