Vetur: Update TypeScript 3.7

Created on 20 Nov 2019  路  5Comments  路  Source: vuejs/vetur

  • [X] I have searched through existing issues
  • [X] I have read through docs
  • [X] I have read FAQ

Info

  • Platform: macOS
  • Vetur version: 0.22.6
  • VS Code version: 1.40.1

Problem

Can't use optional chaining, e.g. a.b?.c

Messages:

Expression expected. Vetur(1109)
':' expected. Vetur(1005)

Reproducible Case

Type this code:

      const a = {}
      console.log(a.b?.c)

Cause, Workaround and Fix

The cause of this problem is the version of Typescript included in Vetur.

There is a workaround by including typescript in your own project and then setting the useWorkspaceDependencies to true in your VSCode settings, as noted in bug report #1503

This workaround is not suitable for general use because:

  1. The issue is of a severity where it causes the program to not compile and there is no way to tell Vetur to ignore the next line or anything like that.
  2. It requires every individual project to have typescript installed to be able to use this language feature
  3. Vetur should work out of the box with the latest language features, so while this is new and not completely ratified, it is already included in the most common browser, Chrome 79+, and there is a readily available polyfill for other browsers. It is also already fully supported in VSCode, so this is the only impediment to using it.

I would therefore ask that rather than just closing the issue because there is a workaround, that you put it on the todo list to implement the fix.

The fix is to upgrade the version of typescript included in Vetur to 3.7+

feature-request typescript

Most helpful comment

We'll activate Dependabot for this repo so that we can release it with the latest TypeScript as soon as we can.

All 5 comments

As far as im aware (and I'm not a VS Code extensions expert), Vetur does not bring its own version of typescript - it uses the one that comes with VSCode.

And since that's the version that all your normal .ts files will be run through by VSCode as well (unless you tell VSCode otherwise), this seems like a sensible default.

@LinusBorg It comes with its own language server which includes typescript (https://github.com/vuejs/vetur/blob/master/server/package.json), but you can tell it to use the workspace version using useWorkspaceDependencies. Unfortunately, what it thinks of as the workspace version is explicitly loaded from the node_modules in your project (see src/services/dependencyService.ts:70) so it doesn't matter what version is included in VSCode and also doesn't pick up a global install of typescript. Therefore the only workaround at the moment is to enable the workspace dependencies setting in VSCode and also to include the typescript library in each project.

We'll activate Dependabot for this repo so that we can release it with the latest TypeScript as soon as we can.

@ktsn That would be nice, as of now using useWorkspaceDependencies with TS 3.7.2 results in intellisense failures.

@Niekvdm
Sorry, I made this comment on the other issue where you posted that. I didn't see that you posted here too.

So, to track things in one place: Can you clarify what is broken for you?

Was this page helpful?
0 / 5 - 0 ratings