Created
December 17, 2019 18:27
-
-
Save carlrip/cc3b08e051b7116747cb21c34d3d0034 to your computer and use it in GitHub Desktop.
Nullish coalescing - before
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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