Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VueJs Typescript ignore typescript error in template block

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>
like image 355
Leon Avatar asked Nov 25 '25 04:11

Leon


2 Answers

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>
like image 149
Rex Pan Avatar answered Nov 26 '25 17:11

Rex Pan


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>
like image 41
Leon Avatar answered Nov 26 '25 16:11

Leon