Hacker News new | past | comments | ask | show | jobs | submit login

Plain vanilla JS (and therefore TypeScript) still lacks one killer feature from the Coffee family: Null propagation operators (`a ? b` => `a != null ? a : b`, `a?.x` => `a == null ? null : a.x`, etc). Even C# has it.



I agree, it's one of the features we'll miss.

There is a Stage 1 Null Propagation proposal: https://github.com/tc39/proposal-optional-chaining


There's a babel transform for this in case you want to start using it now, before browsers support it:

https://github.com/babel/babel/tree/7.0/packages/babel-plugi...


I want to use TypeScript too, which will probably not adopt it until standardization.


We definitely want to implement it! But many parts of that specification are still in flux, so like you said, we'd like to see the proposal stabilize first to avoid problems.


Thanks for the tip! Given some of the lessons we've learned with CoffeeScript, we'll most likely wait until proposals hit at minimum stage 3 before adopting them.


I've been waiting for this for years. Even considered forking Babel... it's been a long time coming :)


Given null is generally non-idiomatic in JS (it's there, but most best practices say to avoid it) I think that's likely by design.

However the `a?.b` form is coming (it's not just null propagation, it's an Existence Operator). It's called "optional chaining"

https://github.com/tc39/proposal-optional-chaining


> I think that's likely by desig

Fine.

s/null/undefined

The problem still exists.


I think calling it a problem is a bit melodramatic.

A cleaner syntax is nice for sure, but it’s not exactly unworkable as is (and promotes flatter data, generally a good thing).

But yes, it’ll be nice if/when the new syntax drops.


The other killer feature that is still missing is multi-line regex with inline comments. I know, you shouldn't be writing big regexes if possible… but when you need to, it's so nice to be able to actually explain what the heck you are doing!


The first one kind of works with `a || b`. Returns b if a is falsey (null, undefined, 0, "").


> kind of works

!== works




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: