-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed as not planned
Closed as not planned
Copy link
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
π Search Terms
TypeGuard
Union
π Version & Regression Information
Works After TS 4.6
β― Playground Link
π» Code
function isNull(x: unknown): x is null{
return x === null;
}
type ErrorUnion<T, U = Error> = [U, undefined] | [null, T]
function test(arg: ErrorUnion<string> ){
const [err, value] = arg
if(!isNull(err)){
throw err;
}
return value // string | undefined
}
function test2(arg: ErrorUnion<string> ){
const [err, value] = arg
if(err !== null){
throw err;
}
return value // string
}
π Actual behavior
The value
variables in test
and test2
are predicted as different types
π Expected behavior
Both value
in test
and test2
should be predicted as string
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created