Do you describe types sparsely?
29/04/2016 5:48 AM by
This comes down to personal preference, but there are only a few times when you must define a type in TypeScript, for example:
- When initializing a variable with an ambiguous value (eg. null)
- Function parameters
Of course, there are also times when you may want to be more explicit – you may want to have an interface as a function return value instead of the class, for example.
The rest of the time, rely on TypeScript to infer the type for you.
- Figure: Except for the input parameter, TypeScript can infer all the types for this function
Do you feel this rule needs an update?