Skip to content

Instantly share code, notes, and snippets.

@eamonnboyle
Created August 27, 2021 10:09
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 eamonnboyle/ed50f3b2d089c6e9c53b31c2dceaf66d to your computer and use it in GitHub Desktop.
Save eamonnboyle/ed50f3b2d089c6e9c53b31c2dceaf66d to your computer and use it in GitHub Desktop.
Assertion Functions
function assertIsTextArea(input: HTMLInputElement | HTMLTextAreaElement): asserts input is HTMLTextAreaElement {
if (!('rows' in input)) {
throw new Error("Expected a HTMLTextAreaElement");
}
}
assertIsTextArea(input);
// If we get to this line, no exception has been thrown
// Therefore, input has type HTMLTextAreaElement
input.rows = 25;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment