Bug Report
๐ Search Terms
Generic types nonnullable
๐ Version & Regression Information
This bug appears to exist ever since NonNullable was introduced (tested from 3.3.3 to 4.5.4)
โฏ Playground Link
Playground link with relevant code
๐ป Code
function throwIfNullable<T>(
value: T,
): NonNullable<T> {
if (value !== undefinedย && value !== null) {
return value;
}
throw Error('Nullable')
}
๐ Actual behavior
The line return value raises a compilation error Type 'T' is not assignable to type 'NonNullable<T>'.
๐ Expected behavior
No compilation error as the if clause properly guards against nullish values