Vue Cli Project Enable Optional Chaining

November 29, 2019

NOTE: You might want to upgrade to latest plugins

Optional Chaining: item?.name.

via Babel

Install

npm install --save-dev @babel/plugin-proposal-optional-chaining

Edit babel.config.ts to add @babel/plugin-proposal-optional-chaining in plugins

module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset'
  ],
  plugins: [
    '@babel/plugin-proposal-optional-chaining'
  ]
}

via TypeScript

npm install typescript@latest

NOTE: Need at least version 3.7.2

Edit tsconfig.json: change target to es2020.

{
  "compilerOptions": {
    // "target": "esnext",
    "target": "es2020",
    ...
  }
}

References:

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.