Last active
June 3, 2021 04:44
-
-
Save Nixinova/0d22a65b0574fc8e8df07c1b07e12491 to your computer and use it in GitHub Desktop.
Simple JavaScript type checking
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
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