-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Proposal: Do expression and async do expression #42437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Cool! |
|
@typescript-bot pack this. |
|
Hey @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 pack this |
|
Hey @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 |
|
@Kingwl hi can you pack this thanks! |
|
@typescript-bot pack this. |
|
Oops, seems I cannot trigger ts bot anymore. @orta might can give some help to you. |
|
@typescript-bot pack this. |
|
Hey @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 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.