Optional chaining is currently not supported in Node.js version 13 and below. It will be supported from Node.js version 14 and most of the browsers as it is moved to Stage 4. Currently, few platforms are supporting it. You can find the list of platforms supporting optional chaining in the given link. You can enable optional using --harmony flag.
Optional chaining is currently not supported in Node.js version 13 and below. It will be supported from Node.js version 14 and most of the browsers as it is moved to Stage 4. Currently, few platforms are supporting it. You can find the list of platforms supporting optional chaining in the given link. You can enable optional using --harmony flag.
The spec for the optional chaining feature was just promoted to Stage 4 (Finished) on December 22, 2019. Node 12 came out before the spec was final - and so did Node 13, for that matter.
According to node.green, optional chaining will be supported starting with Node 14, but will still require the --harmony flag. (This seems to conflict with Node's description of the --harmony flag - V8's shipping features aren't supposed to require the flag - so I'm not sure what to make of that.) Still, whether it needs a flag or not, I wouldn't expect to see the feature until the Node 14 release around April 2020.
If you want to play with optional chaining today, your best bet is to use TypeScript (which added optional chaining in version 3.7) or a preprocessor like Babel.
A feature I've enjoyed in the latest version of JS (at least on the front end) is optional chaining. I find it to be reasonably elegant and time-saving. But it's not supported in Node yet, and I'm not sure the best way to investigate what is "in the works" when it comes to new Node releases.
So, to those who know this kind of stuff, is support for optional chaining on the way?
Thanks everyone. Node is #4 language in all of Kazakhstan.
I have this line of code:
const writeVal = model.default?.({model, config}) || model.default;model is an object Despite the optional chaining operator, this throws an error:
TypeError: model.default is not a function
What's odd is:
I can't replicate this when simulating that line directly in the terminal, via
node -e "globalThis.foo?.("`The error doesn't get thrown if I remove the argument destructuring, i.e. just do
mode.default?.(model, config)
I'm on Node v16.14.2.
Is this a bug, or am I missing something?
» npm install @babel/plugin-proposal-optional-chaining