Skip to content

Instantly share code, notes, and snippets.

@meekg33k
Last active July 1, 2022 13:30
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 meekg33k/d91d2731125ea9606537b0eb6ee5cd15 to your computer and use it in GitHub Desktop.
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)
const isPresentObject = <T>(arg: T): arg is T => {
if (arg && Object.keys(arg).length > 0) {
return true;
}
return false;
}
@npetrini
Copy link

npetrini commented Jul 1, 2022

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

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