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.

Apply templateInterpolationService only to type-checked components

See original GitHub issue
  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

  • 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

Screen Shot 2019-09-11 at 7 37 39 AM

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:open
  • Created 4 years ago
  • Reactions:4
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rchlcommented, Sep 30, 2019

Yes, I have checkJs enabled and I have typechecking enabled in script block. And now I understand your intention and I’m fine with template interpolation only be enabled when @ts-check or checkJs is enabled.

1reaction
ktsncommented, Sep 30, 2019

I feel a bit weird that you expect template type check while <script> block doesn’t (without @ts-check or checkJs in ts compiler). If you are ok with adding type annotation via JS docs, maybe you can just enable checkJs, can’t you?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apply templateInterpolationService only to type ... - Issuehunt
Apply templateInterpolationService only to type-checked components #1427. jackkoppa posted onGitHub. I have searched through existing issues
Read more >
Interpolation Support | Vetur - GitHub Pages
Offer props , data and methods in interpolation regions; Offer :prop completion on child components. # Type Checking with JSDocs. You don't have...
Read more >
Class Components with JSX in NuxtJS - Damir's Corner
Currently, the only way to achieve compile-time type safety is to use render functions with JSX syntax instead. Vue.js Templates. The component ......
Read more >
Switching from React To Vue.js: don't lock yourself in
TypeCheck for Vue. Luckily Vetur provides a working component type checking in VSC by enabling experimental template interpolation service in ...
Read more >
Vetur does not work properly in template(not checking data ...
For anyone who looking for the answer, i had to go to the setting json file and add vetur.experimental.templateInterpolationService: true.
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