Proposal: Do expression and async do expression - #42437
Proposal: Do expression and async do expression#42437Jack Works (Jack-Works) wants to merge 98 commits into
Conversation
|
Cool! |
|
TypeScript Bot (@typescript-bot) pack this. |
|
Heya Wenlu Wang (@Kingwl), I've started to run the tarball bundle task on this PR at 4fad104. You can monitor the build here. |
|
Hey Wenlu Wang (@Kingwl), I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build and an npm module you can use via |
|
TypeScript Bot (@typescript-bot) pack this |
|
Heya Wenlu Wang (@Kingwl), I've started to run the tarball bundle task on this PR at 4277519. You can monitor the build here. |
|
Hey Wenlu Wang (@Kingwl), I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build and an npm module you can use via |
|
Wenlu Wang (@Kingwl) hi can you pack this thanks! |
|
TypeScript Bot (@typescript-bot) pack this. |
|
Oops, seems I cannot trigger ts bot anymore. Orta Therox (@orta) might can give some help to you. |
|
TypeScript Bot (@typescript-bot) pack this. |
|
Heya Orta Therox (@orta), I've started to run the tarball bundle task on this PR at 860f554. You can monitor the build here. |
|
Hey Orta Therox (@orta), I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build and an npm module you can use via |
This reverts commit 6fa966c.
|
Updates:
Orta Therox (@orta) Hi can you let the bot pack this? |
|
Got some problems with |
|
close for now. I'll re-open and rebase this once the proposal gets advanced. |

This is an experimental PR to support ECMAScript proposal do expression.
Proposal: Do expression and Async do expression
Spec: Do expression and Async do expression
PR preview Playground
Known problems / TODOs:
Not all code paths return a valuecheck.breakorcontinueinside theforhead doesn't lead to a type error (there is no spec yet, only a memo so I don't know how to implement this.)Type evaluation rule of the do expression:
I made a change to the checker of typescript. Here are the new evaluation rules:
voidorTypeas a type checking result. If it returns void, it is treated as not contribute to the type of the statement.New type evaluation rules
New Expressions
voidType.Statements
Statement:BlockStatement: type is last type of it's inner statement.VariableStatement: SyntaxErrorEmptyStatement: Does not contribute. See https://tc39.es/ecma262/#sec-block-runtime-semantics-evaluationExpressionStatement: type of it's containing expressionIfStatement: union type of all branches. if there is no else block, it will treated asvoidTypeBreakableStatement:IterationStatement: SyntaxErrorSwitchStatement: union type of all clausesContinueStatement:neverBreakStatement:neverReturnStatement:neverWithStatement:anyLabelledStatement: type of it's inner statementThrowStatement:neverTryStatement: union type oftryclause andcatchclause.finallyclause is ignored.DebuggerStatement: Does not contribute. See https://tc39.es/ecma262/#sec-block-runtime-semantics-evaluationExtra checks
A var declaration cannot be used within a do expression unless the target is ESNext
Not all code paths return a value
Requires
noImplicitReturnsto betrueInlay hints
Show all "exit points" of the do expression to make it easier to identify.