You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a Success / Failure tagged union type called Result, where the tag property is of the one of the two literal types in boolean. Success uses the literal type true and Failure uses the literal type false. I would expect that a test like if (someResult.success) would narrow the type in the else branch to Failure, but it does not.
TypeScript Version: 2.1.4-insiders.20161201 (on the Playground)
Code
typeSuccess<T>={success: true,result: T};typeFailure={success: false,err: Error};typeResult<T>=Success<T>|Failure;// Also possibly a bug - type assertion is necessary too// Otherwise r is upcast to a Success<T> in spite of the type ascriptionconstr: Result<number>={success: true,result: 1}asResult<number>;if(r.success){r.result;}else{r.err}
Expected behavior:
No compilation error
Actual behavior:
Compilation error at the r.err:
Property 'err' does not exist on type 'Result'.
Property 'err' does not exist on type 'Success'.
The text was updated successfully, but these errors were encountered:
I have a
Success
/Failure
tagged union type calledResult
, where the tag property is of the one of the two literal types inboolean
.Success
uses the literal typetrue
andFailure
uses the literal typefalse
. I would expect that a test likeif (someResult.success)
would narrow the type in theelse
branch toFailure
, but it does not.TypeScript Version: 2.1.4-insiders.20161201 (on the Playground)
Code
Expected behavior:
No compilation error
Actual behavior:
Compilation error at the
r.err
:The text was updated successfully, but these errors were encountered: