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
/* Setup */classSuccessResult<T>{success: true=true;constructor(publicvalue: T){}throwOnFailure(): asserts this is SuccessResult<T>{}isSuccess(): this is SuccessResult<T>{returnthis.success;}}classFailureResult<T,EextendsError>{success: false=false;constructor(publicerror: E){}throwOnFailure(): asserts this is SuccessResult<T>{throwthis.error;}isSuccess(): this is SuccessResult<T>{returnthis.success;}}typeOperationResult<T=never,EextendsError=Error>=|SuccessResult<T>|FailureResult<T,E>;functionworkingAssertGuard<T>(result: OperationResult<T>): asserts result is SuccessResult<T>{if(!result.success){throwresult.error}}/* End Setup */constresult: OperationResult<string>={}asOperationResult<string>/* This is the issue */functionassertThisType(){result.throwOnFailure()// type is unchangedresult// OperationResult<string, Error>}/* End of issue *//* The rest below works as intended */functionnarrowOnProperty(){// Working narrowing from propif(result.success){result.value// SuccessResult<string>}else{result.error// FailureResult<string, Error>}}functionassertTypeGuard(){// Working narrowing from Assert Type Guard Function workingAssertGuard(result)result.value// SuccessResult<string>}functionnarrowThisTypeGuard(){// Working narrowing from boolean Type Guard Member Function if(result.isSuccess()){result.value// SuccessResult<string>}else{result.error// FailureResult<string, Error>}}
🙁 Actual behavior
Asserts on this from a member function does not narrow this
🙂 Expected behavior
Asserts on this from a member function does narrow this
The text was updated successfully, but these errors were encountered:
For performance reasons, method-based control-flow-affecting calls need to be immediately (definition left intentionally vague) resolvable to something with an asserts return type to be considered part of the control flow graph. A union type doesn't currently fit that definition, but possibly we could change that.
Thanks @RyanCavanaugh for the explanation. Is there any docs/code that helps explain this? I'd like to look into it some more but wouldn't know where in the codebase to start.
Bug Report
🔎 Search Terms
possibly related to #43368
🕗 Version & Regression Information
Seems to effect all versions
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Asserts on
this
from a member function does not narrowthis
🙂 Expected behavior
Asserts on
this
from a member function does narrowthis
The text was updated successfully, but these errors were encountered: