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 throw expressions #6605

Open
verekia opened this issue Jul 17, 2018 · 4 comments
Open

Support for throw expressions #6605

verekia opened this issue Jul 17, 2018 · 4 comments

Comments

@verekia
Copy link

verekia commented Jul 17, 2018

const fn = () => true ? throw 'true' : throw Error('false')

causes Unexpected token throw.

https://github.com/tc39/proposal-throw-expressions (stage 2)

@friday
Copy link

friday commented Jul 17, 2018

That's because you're returning it. You can't return throw.

@verekia
Copy link
Author

verekia commented Jul 17, 2018

const a = true ? throw 'true' : throw Error('false')

causes the same issue.

@friday
Copy link

friday commented Jul 17, 2018

Sorry. My bad! I thought you were just mistaking throw statements and was really confused why you added this to the ES2015 & 2016 meta-issue.

@Zvax
Copy link

Zvax commented Aug 2, 2019

Not sure if that's the same issue, but I come upon the same error message when using this (I don't believe that being in a constructor has any effect on it, probably any context would be the same, but it's how I encounter it):

constructor() {
    this.param = process.env.ENVIRONMENT_VARIABLE || throw new TypeError(`The ENVIRONMENT_VARIABLE should be set in the environment.`)
}

I use this because I find it nice, and because I want to prevent an object from being instantiated if some values are not present in the environment. There are more verbose ways to achieve that that do not throw flow off, but I would find it neat to keep it that way!

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

Successfully merging a pull request may close this issue.

4 participants