Can't use optional chaining, e.g. a.b?.c
Messages:
Expression expected. Vetur(1109)
':' expected. Vetur(1005)
Type this code:
const a = {}
console.log(a.b?.c)
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:
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+
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?
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.