-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
Bug Report
π Search Terms
object is possibly undefined 4.8
π Version & Regression Information
- This changed between versions 4.7.4 and 4.8.2
β― Playground Link
TS playground on 4.8.0-beta link.
(The playground doesn't seem to have 4.8.x releases, but I tested on 4.8.0-beta and nightly (4.9.0-dev.XXXXXXX).)
π» Code
export function min<T>(it: Iterable<T>): T | null {
let result: T | null = null;
for (const v of it) {
if (result === null || result > v) {
result = v;
}
}
return result;
}
error TS2532: Object is possibly 'undefined'.
if (result === null || result < v) {
~~~~~~
On that line, hovering over the first result
shows T | null
. Hovering over the second result
shows T & ({} | undefined)
.
π Actual behavior
I get a type error.
π Expected behavior
No error.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone