Assert a Value Is a Non-empty String
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write assertIsNonEmptyString(value): do nothing when value is a string with at least one character other than spaces, and throw an Error otherwise (for an empty or blank string, a number, null and so on). Make it an assertion function on unknown, so that after the call the compiler treats value as a string without an if.
Your code must pass
- Lets a non-empty string through
- Throws for empty, blank and non-string values
- Has no type errors
- Narrows unknown to string after the call
- Is an assertion function on unknown