-
Notifications
You must be signed in to change notification settings - Fork 13k
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 value
check.break
orcontinue
inside thefor
head 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:
void
orType
as 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 asvoidType
BreakableStatement
:IterationStatement
: SyntaxErrorSwitchStatement
: union type of all clausesContinueStatement
:never
BreakStatement
:never
ReturnStatement
:never
WithStatement
:any
LabelledStatement
: type of it's inner statementThrowStatement
:never
TryStatement
: union type oftry
clause andcatch
clause.finally
clause 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
noImplicitReturns
to betrue
Inlay hints
Show all "exit points" of the do expression to make it easier to identify.