Created
August 27, 2021 10:09
-
-
Save eamonnboyle/ed50f3b2d089c6e9c53b31c2dceaf66d to your computer and use it in GitHub Desktop.
Assertion 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 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