Closed as not planned
Closed as not planned
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