1

im trying to disable typescript error in vscode from Nuxt, i try to use but its not working, i wanna make lines like this dont get any error in visual code:


   <Reviews :reviewText="reviews.text" :reviewStars="reviews.rating"
       :createdAt="formatDate(reviews.created_at)" 
       :author="reviews.client.name"
       :profilePic="reviews.client.profilePic" class="mx-4">
   </Reviews>

// get error cause i didint check
interface reviews {
    text: string,
    rating: Int32Array,
    created_at: string,
    client: client[]
}

interface client {
    name: string;
    profilePic: string;
}

gets:

Property 'profilePic' does not exist on type '{ name: string; profilePic: string; }[]'.ts(2339)

errors like "'field' is of type 'unknown'." are also comom for me.

This code above works well in the browser, but typescript in vscode and in the terminal claims errors, and its getting really annoying when i try to save lines for v-for or v-ifs, like use "field.relation1.relation2", i just wanna stop ts checking for examples like this, this is what i wanna do.

1 Answers1

2

You're missing something. The types definition suggests 'reviews type' has a list of 'client type'. so the line :profilePic="reviews.client.profilePic" isn't correct. I've added comments above the line where the error is...

 <Reviews :reviewText="reviews.text" :reviewStars="reviews.rating"
   :createdAt="formatDate(reviews.created_at)" 
   :author="reviews.client.name"
   /* notice reviews.client is an array in this case */
   
   :profilePic="reviews.client.profilePic" 
   class="mx-4"
  >
 </Reviews>

// get error cause i didint check
interface reviews {
    text: string,
    rating: Int32Array,
    created_at: string,
    client: client[]
}

interface client {
    name: string;
    profilePic: string;
}

I'll suggest you fix your type definition or if you intend to go ahead with it know that it's a list and use v-for to iterate through the items.

So to recap there's nothing as reviews.client.profilePic from the type definition you have. reviews.client is an array of object containing name and profilePic

I think keeping typescript up in your project is still a good thing but if you're bent over removing it in your files, I think adding tslint:disable on each file could help. You can also check this question out on stackoverflow

Samson Iyanda
  • 512
  • 3
  • 13