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

Idea: Required property accessor #1221

Closed
adrianhelvik opened this Issue Jun 8, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@adrianhelvik

adrianhelvik commented Jun 8, 2018

It would be nice to have foo!.bar alongside foo?.bar.

foo!.bar could then throw if foo.bar === undefined.

Useful when using process.env in Node and for debugging. Its primary use case would be for when undefined is unacceptable:

sendEmailToUsers({
  from: process.env!.customerSupport
})

The reason I think allowing nulls is a good idea is that they are generally explicitly specified, whereas undefined is usually not what you want.

@adrianhelvik adrianhelvik changed the title from Required property accessor to Idea: Required property accessor Jun 8, 2018

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Jun 8, 2018

Member

Please see the proposal repo for optional chaining, as well as https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md for how to best suggest new ideas.

Separately, foo?.bar tells you something about foo, not bar - as such, foo!.bar would have to have behavior based on foo - not foo.bar - for consistency.

Member

ljharb commented Jun 8, 2018

Please see the proposal repo for optional chaining, as well as https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md for how to best suggest new ideas.

Separately, foo?.bar tells you something about foo, not bar - as such, foo!.bar would have to have behavior based on foo - not foo.bar - for consistency.

@ljharb ljharb closed this Jun 8, 2018

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