Typescript checking in Vue SFCs does not work as expected
See original GitHub issueIn 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:
- Created 3 years ago
- Reactions:34
- Comments:18 (6 by maintainers)
Top GitHub Comments
@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.
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