Last active
July 1, 2022 13:30
-
-
Save meekg33k/d91d2731125ea9606537b0eb6ee5cd15 to your computer and use it in GitHub Desktop.
Code snippet for TypeScript Type Guards and Generics (Read full article here https://medium.com/p/177b4a654ef6)
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
const isPresentObject = <T>(arg: T): arg is T => { | |
if (arg && Object.keys(arg).length > 0) { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sorry for the late comment (only 2 years after) but, according to my understanding, this type guards only ensure that arg is not undefined or empty but not at all that arg is T