Skip to content
Advertisement

Vue 3 recommended TypeScript TSConfig compilerOptions TARGET setting?

This question has puzzled me at several points when using Vue 2 and Vue CLI, and now again with starting a fresh Vue 3.0 beta project.

Even with the currently newest Vue CLI version 4.3.1, when choosing TypeScript option, the boilerplate code you are given has compilerOptions target set as esnext in tsconfig.json.

While Vue 2 TypeScript Guide is instructing:

# Recommended Configuration
// tsconfig.json
{
  "compilerOptions": {
    // this aligns with Vue's browser support
    "target": "es5",
    // this enables stricter inference for data properties on `this`
    "strict": true,
    // if using webpack 2+ or rollup, to leverage tree shaking:
    "module": "es2015",
    "moduleResolution": "node"
  }
}

Currently Vue Next repo is using esnext, although at this point IE11 support is not ready yet (but might not affect this config anyhow)…

What will be the recommended setting for this compiler target when using Vue 3?

I’m needing to support legacy browsers down to IE11, but this particular app project has plenty of time until it’s initial release to wait for Vue 3’s full release.

Advertisement

Answer

As Vue 3 repository states,

the current implementation requires native ES2015+ in the runtime environment and does not support IE11 (yet). The IE11 compatible build will be worked on after we have reached RC stage.

As it was noted, the target of Vue 3 is currently esnext, it relies on modern JS features and is currently aimed at the development in evergreen browsers and isn’t supposed to be used in production. Vue 3 cannot be usable in legacy browsers even with lower target because it currently relies on proxies which are ES6 feature that cannot be polyfilled.

The project that uses existing Vue 3 build won’t benefit from target lower than es2018 which is likely the least common denominator, object spread is among most popular recent additions that is used in Vue 3 codebase and cannot be polyfilled. TypeScript target can be experimentally lowered to es5 with downlevelIteration option enabled for early detection of some compatibility problems.

It’s expected that separate versions of Vue 3 will be maintained for legacy (IE11) and modern browsers. The difference is how reactivity is handled because Proxy allows for advanced change detection but cannot be implemented in legacy browsers. The project should follow existing guidelines for Vue 2 reactivity in order to be compatible with legacy Vue 3 build.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement