Created
July 7, 2022 21:18
-
-
Save joshuacerbito/57dc688b35a6a59451ee5363c664f009 to your computer and use it in GitHub Desktop.
[TS] ensure function to fix "T | undefined" from Array functions
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 ensure<T>(argument: T | undefined | null, message: string = 'This value was promised to be there.'): T { | |
if (argument === undefined || argument === null) { | |
throw new TypeError(message); | |
} | |
return argument; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment