question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript checking in Vue SFCs does not work as expected

See original GitHub issue

In the docs (README) under the Typescript section, it says:

[Vite] does NOT perform type checking. It assumes type checking is taken care of by your IDE and build process (you can run tsc --noEmit in the build script).

However, running tsc --noEmit is problematic.

Firstly, if you turn on isolatedModules in your tsconfig, then tsc will fail, because Vue exports const enums (there’s a bug reported in the Vue repo about that). You can just turn this flag off, but then you have to be careful not to use stuff that wouldn’t work outside a module.

Secondly, even if you include .vue files in your tsconfig, they do not get type checked. Since the majority of your code is in SFCs (if you use them) in a Vue app, this makes it pointless.

In a webpack build with Vue CLI setup, the script portion of SFCs is transpiled with babel (similar to using esbuild here) and checked with typescript, using ts-loader or similar. In Vite, this isn’t happening, so the docs are misleading.

Since Vue 3 is built in Typescript, more people are likely to use TS going forwards, people moving from Angular to Vue are likely to start with TS, so there really needs to be solid support for it. I appreciate that the build process doesn’t need it, but type checking is still important. Whilst the IDE can warn you, in any professional set up, it needs to be part of the CI process, so a way to configure tsc to do this is necessary.

Is there a way to get type checking of SFCs? Minimum the script part, but ideally the code within templates too.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:34
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

9reactions
spikyjtcommented, Aug 28, 2020

@robyedlin I see how this conversation is slightly related to the one you link, but that is talking about wider features such as unit testing being configured out of the box. I appreciate those things might be non goals as commented by Evan, because this is just supposed to be a build tool. However, type checking is very much a (necessary) part of the build process, so it is relevant. I’d be interested to know if @yyx990803 thinks this is also a non goal and why.

Another commenter on that thread suggested that they preferred using the IDE for type checking and not duplicating the functionality. That’s all very well for single developers or very small teams, but completely unacceptable at scale. Also many of the IDE plugins are buggy and miss things.

@underfin is this yet another - I don’t need this, because I don’t use it, therefore I’ll just close it? If it needs doing (I think it really does) then it still remains a missing feature at least, so should be left open. IMHO it’s actually a bug, as the primary use case of this library is for building Vue 3, which is written in Typescript and so should support its proper use. Since the docs mention Typescript support and that if you want to do type checking, you just run tsc --noEmit then this should actually work, have docs to show how it can work, or be made very clear that it will never work.

I totally get that we want to be able to do transpiling as quickly as possible, but without actually doing type checking at some point, there really is no purpose to using Typescript.

5reactions
andreasvirkuscommented, Sep 18, 2020

I’d like to second that maybe this would be more appropriately labelled as a bug instead, since Vite lists TypeScript as one of its biggest features in the readme

Read more comments on GitHub >

github_iconTop Results From Across the Web

I can't figure out how to get TypeScript checking on <script ...
Intuitively, the last line in this snippet should cause an error — assigning a string to a number variable is not permitted. However...
Read more >
TypeScript errors when editing old Vue 3 components but ...
I was able to fix these import errors by upgrading TypeScript from 3.9.3 to 4.4.4: npm install typescript@latest. It seems that Vue 3.2.0 ......
Read more >
Vue.js Single File Component Typescript Not Showing Errors
Problem is typescript is not showing any errors at the editor, ... Since then, type checking in .vue SFC files periodically stops working....
Read more >
Features
Vite only performs transpilation on .ts files and does NOT perform type checking. It assumes type checking is taken care of by your...
Read more >
How to use Vue 3 with TypeScript
Open localhost:8080 or whatever URL your console shows after starting the project, and you should see your app running successfully. For each ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found