Created
January 17, 2022 15:36
-
-
Save vinhlee95/e8f3b1782593d4111471838bec11f248 to your computer and use it in GitHub Desktop.
This file contains 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
const getKeys = (obj: unknown) => { | |
return Object.keys(obj as object) // <- cast the type to be object | |
} | |
const getObject = (): object | undefined => { | |
// some code that return EITHER an object OR undefined 💣💣💣 | |
} | |
getKeys(getObject()) // <- 💣💥 when getObject() returns undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment