Skip to content

Instantly share code, notes, and snippets.

@ofbeaton
Last active April 14, 2019 02:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ofbeaton/663deb0d7ed943e45bc32bf8432361b3 to your computer and use it in GitHub Desktop.
Save ofbeaton/663deb0d7ed943e45bc32bf8432361b3 to your computer and use it in GitHub Desktop.
Typescript Default value when null is returned from a function call

In the case of a function that returns a value or null, and for which you want an initial value, you'll need to use a combination of concepts to keep it to a one liner and keep typescript happy.

Most answers on stack say turn off strict nulls. No.

(var && func(var)) || default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment