Home > Blockchain >  Missing return Type on Function in Vue 3 with Typescript
Missing return Type on Function in Vue 3 with Typescript

Time:11-26

My code looks like this,

    <template>
      <div>        
        <ul v-if="list.length !== 0">
          {{
            list
          }}
        </ul>
      </div>
    </template>
    <script>
    export default {
      props: {
        
        list: {
          type: Array,
          default: () => {
            return []
          },
        },
        
      },
    }
    </script>

Am I missing something, because I am getting error on this line:

Error screenshot

I also tried solution from this page, but nothing works.

Vue 2 - How to set default type of array in props

CodePudding user response:

This is not an error, but a warning that the anonymous function should indicate a return type. Your IDE shows the name of the check, and searching for it leads to a page with good examples.

The warning should be fixed like this:

list: {
  type: Array,
  default: ():Array => {
    return []
  },
},

CodePudding user response:

As error said, you are missing function return type. You defined prop type, but not function return type.

It should look like this (in place of any you should also specify type):

export default {
  props: {
    list: {
      type: Array,
      default: () : Array<any> => {
        return []
      },
    },
  },
}
  • Related