-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed as not planned
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
π Search Terms
Possibly undefined compiler checks
π Version & Regression Information
- This is the behavior in every version I tried, including 5.8.0 nightly, and checked the FAQ. I did not find anything about this error.
β― Playground Link
π» Code
interface IType {
i: number;
}
function test(v1: null | undefined | IType, v2: null | undefined | IType): boolean
{
// if both v1 and v2 are undefined, quit here
if (v1 === undefined && v2 === undefined) {
return true;
}
// if any of v1 or v2 is undefined, and the other is not
// we're quitting here, so below this line neither v1 nor v2 can be undefined
if (v1 !== v2) {
return false;
}
// filter out if any variable is null
if (v1 === null || v2 === null) {
return false;
}
return v1.i === v2.i;
}π Actual behavior
In the last code line the compilers throws an error, that v1 and v2 both could be undefined, but as commented in the code section they never will be undefined here.
π Expected behavior
Do not throw errors like 'v1' is possibly 'undefined'. ts(18048)
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created