How to declare Return Types for Functions in TypeScript

Posted by Jessica Taylor | Updated on

If you want to declare Return Types for Functions in TypeScript? Below is a fully working example – you’ll see that var result is implicitly a string because the return type is specified on the greet() function. Change the type to number and you’ll get warnings.

Here is the number example – you’ll see red squiggles in the playground editor if you try this:

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers