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
Allow functions and methods of the signature (...args: any[]) => Promise<asserts condition> which mean that condition is true if the promise resolves.
π Motivating Example
Sometimes it is necessary to call asynchronous functions to make sure that some field is assigned. For instance, a somewhat common pattern is to have an async ensureFieldX(): Promise<void> method and it would be nice if typescript knew that after that method has resolved (and not rejected).
classFoo{privatebar: string|undefined;asyncgetBar(): Promise<string>{awaitthis.ensureBar();returnthis.bar;}privateasyncensureBar(): Promise<assertsthis is (Foo&{bar: string})>{
...
}}
π» Use Cases
See motivating example...
Could also be extended to asynchronous user defined type guards but I don't think that is as important.
The text was updated successfully, but these errors were encountered:
Suggestion
π Search Terms
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
Allow functions and methods of the signature
(...args: any[]) => Promise<asserts condition>
which mean thatcondition
is true if the promise resolves.π Motivating Example
Sometimes it is necessary to call asynchronous functions to make sure that some field is assigned. For instance, a somewhat common pattern is to have an
async ensureFieldX(): Promise<void>
method and it would be nice if typescript knew that after that method has resolved (and not rejected).π» Use Cases
See motivating example...
Could also be extended to asynchronous user defined type guards but I don't think that is as important.
The text was updated successfully, but these errors were encountered: