Reputation: 733
I’m a newbie in Typescript and in programming in general.
Instead of this:
function greet(greeting: string): void;
Can I use something like this? Is there any kind of inference?
function greet(greeting: string)
Upvotes: 0
Views: 55
Reputation: 4741
Yes, in 95% of cases TypeScript will correctly infer the return type of a function. Exceptions to this include "tuples", which will be inferred as arrays, and anonymous objects which you may have already declared a type for.
In this case, no need to explicitly declare the return type as void
, except for clarity of course.
Upvotes: 3