Skip to content

Instantly share code, notes, and snippets.

@carlrip
Created December 17, 2019 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlrip/cc3b08e051b7116747cb21c34d3d0034 to your computer and use it in GitHub Desktop.
Save carlrip/cc3b08e051b7116747cb21c34d3d0034 to your computer and use it in GitHub Desktop.
Nullish coalescing - before
type Person = {
id: number;
name: string;
score?: number;
}
function getPersonScore(id: number): number {
const person: Person = getPerson(id);
return person.score; // 💥 - Type error - Type 'number | undefined' is not assignable to type 'number'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment