-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Closed
Copy link
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdFix AvailableA PR has been opened for this issueA PR has been opened for this issue