Skip to content

Support 'throw' expressions #18535

Closed as not planned
Closed as not planned
@brn

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

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