Open
Description
TypeScript Version: 3.7.0-dev.20191002
Search Terms: assertion signatures, asserts, not checked, unchecked, unsound
Code
function assertIsString(x: number | string): asserts x is string {
}
function test(x: number | string) {
assertIsString(x);
x.toUpperCase();
}
test(4);
Expected behavior:
This incorrect empty implementation of assertIsString
should not type check, because there are execution paths through assertIsString
that don’t narrow the type of x
to string
as the type of assertIsString
should require.
Actual behavior:
No TS errors. Compiled JS code fails at runtime: TypeError: x.toUpperCase is not a function
.
Playground Link: Playground nightly isn’t new enough, but maybe it will be by the time you read this: link.
Related Issues: