Skip to content
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

Support for ECMAScript 'do'-expressions #13156

Open
CodySchaaf opened this issue Dec 24, 2016 · 16 comments
Open

Support for ECMAScript 'do'-expressions #13156

CodySchaaf opened this issue Dec 24, 2016 · 16 comments
Labels
ES Next New featurers for ECMAScript (a.k.a. ESNext) Suggestion An idea for TypeScript Waiting for TC39 Unactionable until TC39 reaches some conclusion

Comments

@CodySchaaf
Copy link

CodySchaaf commented Dec 24, 2016

Sorry if this has been discussed but it is hard to search for such a generic combination of words.

Is there any plan to implement support for https://github.com/tc39/proposal-do-expressions http://wiki.ecmascript.org/doku.php?id=strawman:do_expressions

It would be awesome to be able to avoid the extra code required when wrapping an if statement in a function to get a dynamic return value.

Thanks!

@aluanhaddad
Copy link
Contributor

These could be quite pleasant to use but unfortunately the proposal is still at Stage 0 in TC39.

@DanielRosenwasser DanielRosenwasser changed the title Support for do expressions ECMAScript proposal Support for ECMAScript 'do'-expressions Dec 24, 2016
@DanielRosenwasser DanielRosenwasser added ES Next New featurers for ECMAScript (a.k.a. ESNext) Suggestion An idea for TypeScript labels Dec 24, 2016
@zpdDG4gta8XKpMCd
Copy link

I wish it was haskell's do notation

@geverges-oleg
Copy link

+1

@steve8708
Copy link

looks like this is now in TC39 stage 1 🎉

@zheeeng
Copy link

zheeeng commented Aug 17, 2017

+1 @aluanhaddad What's the accepting standard for ex-next? Is stage 2+ or stage 1 is ok?

@aluanhaddad
Copy link
Contributor

TypeScript tends to adopt proposals once they reach stage 3 in TC39.

This is not a hard and fast rule and there are exceptions such as async/await, which turned out really well, and Decorators, which need a massive overhaul.

@IamManchanda
Copy link

As discussed in #20743, I think this should be added in typescript now I really feel so :)

Using kotlin for quite some time and similar syntax for this is quite productive

    message = when {
        (age < 18) -> "You are too young to vote"
        (age == 100) -> "Congratulations"
        else -> "You can vote"
    }

@aluanhaddad
Copy link
Contributor

aluanhaddad commented Jan 29, 2018

@IamManchanda see proposal-pattern-matching.

@RyanCavanaugh RyanCavanaugh added the Waiting for TC39 Unactionable until TC39 reaches some conclusion label Aug 15, 2018
@drhumlen
Copy link

Any progress on this one?

@vipcxj
Copy link

vipcxj commented Apr 19, 2019

Any progress on this one?
do expression is very very very useful for react project.

@G-Rath
Copy link

G-Rath commented Apr 19, 2019

@vipcxj Please check the stage of the proposal. Currently, it is still at stage-1, meaning it's in the proposal stage.

This means that the syntax is still being drafted, and thus subject to wild changes.

TS doesn't like to adopt TC39 proposals until they're at least candidates (stage 3). Sometimes they'll implement draft (stage 2), but its very rare, and something they're actively trying to avoid.

You should wait until the proposal is at least in draft status before adopting it.

@alamothe
Copy link

alamothe commented May 2, 2019

do expression seems unnatural. Why not just let any statement be an expression, like in Kotlin?

This could be a part of TypeScript itself, so no need to wait on JavaScript proposal. Thoughts?

@xialvjun
Copy link

xialvjun commented Jul 12, 2019

I'm curious about why we need do in do expression, why not just make any statement be an expression...

import h from 'hyperscript';
import o from 'observable';

const root = h('div', {
  const count = o(0);
  [
    h('h1', {title: count}, count),
    h('button', { onclick: e => count(count()+1) }, 'add 1')
  ]
});

document.body.append(root);

@RyanCavanaugh
Copy link
Member

Please discuss the proposal in the proposal repo, not here

Thanks!

@avin-kavish
Copy link

Is there a way to stop the typescript language server from erroring on do expressions? Asking because I'm using babel to transpile do expressions but the ts language server in the IDE is complaining about it.

@fullofcaffeine
Copy link

Is there a way to stop the typescript language server from erroring on do expressions? Asking because I'm using babel to transpile do expressions but the ts language server in the IDE is complaining about it.

I'd like to know about this, too ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ES Next New featurers for ECMAScript (a.k.a. ESNext) Suggestion An idea for TypeScript Waiting for TC39 Unactionable until TC39 reaches some conclusion
Projects
None yet
Development

No branches or pull requests