镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Support 'throw' expressions #18535

Description

@brn

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!') })();
}

Activity

  1. kitsonk commented on Sep 17, 2017

    @kitsonk
    Contributor

    Just to note, Ron Buckton (@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.

  2. brn commented on Sep 17, 2017

    @brn
    Author

    Kitson Kelly (@kitsonk) That make sense.
    So is this proposal premature?

  3. changed the title [-]Support throw-expressions[/-] [+]Support 'throw' Expressions[/+] on Sep 17, 2017
  4. changed the title [-]Support 'throw' Expressions[/-] [+]Support 'throw' expressions[/+] on Sep 17, 2017
  5. DanielRosenwasser commented on Sep 17, 2017

    @DanielRosenwasser
    Member

    So is this proposal premature?

    Nope, it's fine to track it here. Like Kitson Kelly (@kitsonk) said, Ron Buckton (@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. 😄

  6. rbuckton commented on Sep 18, 2017

    @rbuckton
    Contributor

    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.

  7. brn commented on Sep 18, 2017

    @brn
    Author

    Daniel Rosenwasser (@DanielRosenwasser) Ron Buckton (@rbuckton)
    I got it.
    Thank you for the detailed explanation!

  8. Yogu commented on May 11, 2018

    @Yogu
    Contributor

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

  9. rbuckton commented on May 12, 2018

    @rbuckton
    Contributor

    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.

  10. Yogu commented on May 12, 2018

    @Yogu
    Contributor

    Ah, I see. Thanks, Ron Buckton (@rbuckton)!

  11. lufzle commented on Jun 24, 2019

    @lufzle

    This is now in stage 3 :)

  12. rbuckton commented on Jun 24, 2019

    @rbuckton
    Contributor

    No, this has not yet advanced to Stage 3.

  13. locked and limited conversation to collaborators on Jun 25, 2019
  14. RyanCavanaugh commented on Mar 15, 2024

    @RyanCavanaugh
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ES NextNew featurers for ECMAScript (a.k.a. ESNext)SuggestionAn idea for TypeScriptWaiting for TC39Unactionable until TC39 reaches some conclusion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions