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
// Three functions and their return typesfunctionordinaryFunction(){return42;}// returns numberfunction*generatorFunction(){yield42;}// returns IterableIterator<number>asyncfunctionasyncFunction(){return42;}// returns Promise<number>// Assign result to compatible interface type - behaviour is consistentvaro1: number=ordinaryFunction();// OKvaro2: any=ordinaryFunction();// OKvarg1: Iterable<number>=generatorFunction();// OKvarg2: any=generatorFunction();// OKvara1: PromiseLike<number>=asyncFunction();// OKvara2: any=asyncFunction();// OK// Annotate result with compatible interface type - behaviour is inconsistentfunctionof1(): number{return42;}// OKfunctionof2(): any{return42;}// OKfunction*gf1(): Iterable<number>{yield42;}// OKfunction*gf2(): any{yield42;}// OKasyncfunctionaf1(): PromiseLike<number>{return42;}// ERRORasyncfunctionaf2(): any{return42;}// ERROR
This behaviour seems to be by design but the inconsistency is annoying. There is no 'in principle' justification for different treatment of the last two examples.
This has been discussed on #5911 but the consensus there on fixing the bug seems like it might involve just changing the error message text.
I think it should be possible to make the last two examples work consistently like the rest without affecting the special type-directed emit behaviour of async function return type annotations, along the lines suggested here and here. It would involve a non-breaking relaxation of the current over-strict behaviour.
The text was updated successfully, but these errors were encountered:
I would appreciate it if you can keep the discussion to one issue in the future.
As discussed in #5911, this matches the design. There are already two other issues on this topic where we have discussed the design, so le's keep it there.
Sorry @mhegazy it must look like I'm trolling but that's not my intention. I genuinely thought the issue described here was not being considered in #5911 as per the comments here and here. I would just like this specific issue to receive due consideration. If that can go on in #5911 then that's fine.
This behaviour seems to be by design but the inconsistency is annoying. There is no 'in principle' justification for different treatment of the last two examples.
This has been discussed on #5911 but the consensus there on fixing the bug seems like it might involve just changing the error message text.
I think it should be possible to make the last two examples work consistently like the rest without affecting the special type-directed emit behaviour of async function return type annotations, along the lines suggested here and here. It would involve a non-breaking relaxation of the current over-strict behaviour.
The text was updated successfully, but these errors were encountered: