Loading...
function assertString(value: unknown): boolean {
return typeof value === 'string';
}function assertString(value: unknown): asserts value is string {
if (typeof value !== 'string') {
throw new TypeError('Expected a string');
}
}An assertion function throws on failure, and asserts value is string narrows the value after the call.
false instead of throwing, so the narrowing lies to the compiler.asserts value is T or asserts condition, and the function throws when the check fails.Use a predicate for if checks. Use an assertion when invalid input should stop execution with an error.
No, its return type is the asserts clause, so it either returns nothing or throws.