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 'throw' expressions #18535

Closed
brn opened this issue Sep 17, 2017 · 11 comments
Closed

Support 'throw' expressions #18535

brn opened this issue Sep 17, 2017 · 11 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

@brn
Copy link

brn commented Sep 17, 2017

Support proposal-throw-expressions.
That proposal is now stage-1, but worth to implements for convenience and this proposal not break backward-compatibilities.

Current

ts

const errorThrowExp = () => { throw new Error('Error!'); }
function errorThrowFn(maybeTrue) {
  if (maybeTrue){ 
    return ...;
  } else {
    throw new Error('Error!');
  }
}

js

const errorThrowExp = function() {throw new Error('Error!')}
function errorThrowFn(maybeTrue) {
  if (maybeTrue){ 
    return ...;
  } else {
    throw new Error('Error!');
  }
}

Proposal

ts

const errorThrower = () => throw new Error('Error!');
function errorThrowFn(maybeTrue: boolean) {
  return maybeTrue? ...: throw new Error('Error!');
}

js

const errorThrower = function() { throw new Error('Error!'); }
function errorThrowFn(maybeTrue: boolean) {
  return maybeTrue? ...: (function() { throw new Error('Error!') })();
}
@kitsonk
Copy link
Contributor

kitsonk commented Sep 17, 2017

Just to note, @rbuckton is closely aligned to the TypeScript team. I highly suspect this proposal would be implemented when everyone is comfortable it is in a stable enough position.

@brn
Copy link
Author

brn commented Sep 17, 2017

@kitsonk That make sense.
So is this proposal premature?

@DanielRosenwasser DanielRosenwasser added ES Next New featurers for ECMAScript (a.k.a. ESNext) Suggestion An idea for TypeScript labels Sep 17, 2017
@DanielRosenwasser DanielRosenwasser changed the title Support throw-expressions Support 'throw' Expressions Sep 17, 2017
@DanielRosenwasser DanielRosenwasser changed the title Support 'throw' Expressions Support 'throw' expressions Sep 17, 2017
@DanielRosenwasser
Copy link
Member

So is this proposal premature?

Nope, it's fine to track it here. Like @kitsonk said, @rbuckton is championing it and is part of our team, but we will need it to reach a later stage before adopting it in TypeScript.

For what it's worth, I'd be willing to bet he has a branch with an implementation of throw-expressions. 😄

@rbuckton
Copy link
Member

https://github.com/Microsoft/TypeScript/tree/throwOperator?files=1

Currently it does not yet support unreachability checks at the expression level. Also, I am waiting for the next TC39 meeting to see if the proposal moves to Stage 2.

@brn
Copy link
Author

brn commented Sep 18, 2017

@DanielRosenwasser @rbuckton
I got it.
Thank you for the detailed explanation!

@Yogu
Copy link
Contributor

Yogu commented May 11, 2018

The proposal is now in stage 2 - would be cool if this gets implemented in TypeScript.

@rbuckton
Copy link
Member

TypeScript's current stance is that we will not adopt a proposed JavaScript feature until it has reached Stage 3. Currently, Stage 3 for throw expressions is blocked from advancement due to overlap with the do expressions proposal.

@Yogu
Copy link
Contributor

Yogu commented May 12, 2018

Ah, I see. Thanks, @rbuckton!

@luisfarzati
Copy link

This is now in stage 3 :)

@rbuckton
Copy link
Member

No, this has not yet advanced to Stage 3.

@microsoft microsoft locked and limited conversation to collaborators Jun 25, 2019
@RyanCavanaugh
Copy link
Member

Closing since there's nothing for us to do but wait for TC39

@RyanCavanaugh RyanCavanaugh closed this as not planned Won't fix, can't repro, duplicate, stale Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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

Successfully merging a pull request may close this issue.

7 participants