Although this library supports expectType<never>(...), the expectType function returns void
This new expectNever function instead returns never.
This is great for asserting that all branches are being handled in your code
function handleFoo(foo: 1 | 2): boolean {
if (foo === 1) {
return true;
}
if (foo === 2) {
return false;
}
expectNever(foo); // note: expectType<never>(foo) here would give an error
}
There is a library called assert-never that provides this functionality, but it's strange I would need a separate library to assert never vs. asserting other types
Although this library supports
expectType<never>(...)
, theexpectType
function returns voidThis new
expectNever
function instead returnsnever
.This is great for asserting that all branches are being handled in your code
There is a library called assert-never that provides this functionality, but it's strange I would need a separate library to assert never vs. asserting other types