Do you describe types sparsely?

Last updated by Brady Stroud [SSW] 7 months ago.See history

This comes down to personal preference, but there are only a few times when you must define a type in TypeScript, for example:

  1. When initializing a variable with an ambiguous value (eg. null)
  2. 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.

describe
Figure: Except for the input parameter, TypeScript can infer all the types for this function

Steve Leigh
We open source.Loving SSW Rules? Star us on GitHub. Star
Stand by... we're migrating this site to TinaCMS