Apply templateInterpolationService only to type-checked components
See original GitHub issueInfo
- Platform: macOS
- Vetur version: 0.22.2
- VS Code version: 1.38.0
Problem
Feature Request - add a third option for templateInterpolationService
, ts-only
As mentioned in #1246, the templateInterpolationService
works well in a lot of cases, but will quite regularly throw errors for JavaScript components, because without proper attention paid to adding type annotations to a component using lang="ts"
, it’s very unlikely that a JS Vue component will be able to be parsed correctly.
So, in JS components, there are a lot of errors that end up looking like this, when setting "vetur.experimental.templateInterpolationService": true
In our case, and potentially other repos that are attempting to get TS benefits in a codebase that was originally JS-only, some components are TS, while many remain JS.
It seems likely that only TS components will see useful benefits from templateInterpolationService
,
so the proposal is to add a third option to the settings, ts-only
Changing these lines to something like
"vetur.experimental.templateInterpolationService": {
"type": ["boolean", "string"],
"default": false,
"description": "Enable template interpolation service that offers diagnostics / hover / definition / references. Use 'ts-only' to enable only for TypeScript components"
}
I’m sure the above can be done much better, hopefully with enum
, while still maintaining backwards compatibility (default still false
, still allowing true
& applying to all files).
I’m very happy to work on this change, if it’s an acceptable request & the use case (JS & TS components in the same project, or at least the same workspace) is common enough. I don’t have any significant extension development experience, so any other recommendations on how to structure the config option are welcome.
Reproducible Case
(happy to add a modified Veturpack with both JS & TS components, if that’s useful)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:9 (3 by maintainers)
Top GitHub Comments
Yes, I have
checkJs
enabled and I have typechecking enabled inscript
block. And now I understand your intention and I’m fine with template interpolation only be enabled when@ts-check
orcheckJs
is enabled.I feel a bit weird that you expect template type check while
<script>
block doesn’t (without@ts-check
orcheckJs
in ts compiler). If you are ok with adding type annotation via JS docs, maybe you can just enablecheckJs
, can’t you?