Skip to content

Instantly share code, notes, and snippets.

@Nixinova
Last active June 3, 2021 04:44
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 Nixinova/0d22a65b0574fc8e8df07c1b07e12491 to your computer and use it in GitHub Desktop.
Save Nixinova/0d22a65b0574fc8e8df07c1b07e12491 to your computer and use it in GitHub Desktop.
Simple JavaScript type checking
function _(type, val) {
if (!(val instanceof type) && (type(val) !== val))
throw new TypeError(`${JSON.stringify(val)} is not assignable to type "${type.name}"`);
return val;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment