Skip to content

Instantly share code, notes, and snippets.

@joshuacerbito
Created July 7, 2022 21:18
Show Gist options
  • Save joshuacerbito/57dc688b35a6a59451ee5363c664f009 to your computer and use it in GitHub Desktop.
Save joshuacerbito/57dc688b35a6a59451ee5363c664f009 to your computer and use it in GitHub Desktop.
[TS] ensure function to fix "T | undefined" from Array functions
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