20

In my VueJs App everything works as expected. Only thing annoying me is a typescript error in my template block. Is there any option similar to what I would do in my script block?

<script setup lang="ts">
//@ignore-ts
this line will be ignored of typescript errors
</script>

<template>
<!-- @ignore-ts -->
this does not work and this line still has a typescript error
</template>
0

4 Answers 4

50

You can use <!-- @vue-ignore --> #3215. For example:

<template>
  <!-- @vue-ignore -->
  <HelloWorld :msg="wrongType" />

  <!-- @vue-expect-error Describe your error here -->
  <HelloWorld :msg="wrongType" />

  <!-- @vue-skip -->
  <SomethingYouDontWantVolarToRecognizeIt>
    ...
  </SomethingYouDontWantVolarToRecognizeIt>
</template>
Sign up to request clarification or add additional context in comments.

Comments

16

I found my solution finally. //@ts-ignore is still the solution for my problem but most importantly an Enter afterwards makes its magic happen.

If a typescript error annoys you in a v-if="",v-model="",v-for="" etc. in your template block, you can ignore it like this:

Typescript error throwing line of code:

<div v-if="value.input_type === 'text'">

Typescript error ignoring lines of code:

<div v-if="//@ts-ignore 
    value.input_type === 'text'">

If a typescript error annoys you in a mustache i.e. double curly braces in your template block do this:

Typescript error throwing line of code:

<h3>{{value.label }}</h3>

Typescript error ignoring lines of code:

<h3>{{//@ts-ignore
       value.label }}</h3>

9 Comments

reporting that this didn't work for me using vue: "^3.2.47". instead i moved the logic that was displaying a type-check error out of the <template> by creating a const ref() in the <script> and utilizing //@ts-ignore on the line directly above.
How do I do this for directives? <template v-slot:[`item.actions`]="{ item }"> Array brackets generate a TS 2538 error Type 'string[]' cannot be used as an index type.
I would try one of these two options 1. <template v-slot:[`//@ts-ignore \n i.e. new line here item.actions`]="{ item }"> 2. <template v-slot:[`item.actions`]={//@ts-ignore \n i.e. new line here item }"> Does this work for you?
The proper fix is to solve the underlying typescript error. There's always a way to instruct Typescript of your intentions so you allow it to keep doing its job. That's the question you should have asked, IMHO. The only time you'd want to shut Typescript up would be with a false positive, which should be reported to Typescript anyways, so it gets fixed.
@tao I completely agree with you. However, when I posted this I was learning Vue AND Typescript and I was happy everything was running in my app in Vue and the only thing missing was that one annoying Typescript error I had to get rid of by understanding Typescript well enough. I think thats the main situation when people are looking for this thread. I see this as an interim solution for development.
|
0

The error probably shown by TSLint/ESLint, so you can disable this validations. You can use

/* tslint:disable */ 

and

/* tslint:enable */

(this can be applied only on the line or block that have errors. Or you can only disable specifics rules, see more details here

But, I strongly recommend to you search about the error and if there are a correct way to implement it (I know it doesn't always have)

1 Comment

Thanks for your answer! But this doesn't help me yet. If I use /* tslint:disable */ in my <script>-block, there is still an error thrown in my <template> block. I have posted my actual typescript problem in this question if you might want to check it.
0

Had to use in my specific case:

<component
  :is="component"
  @save-settings="
    $e =>
      saveSettings(
        /* @ts-ignore Argument of type 'unknown' is not assignable to parameter */
        $e,
      )
  "

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.