6
'use strict'

import Vue from 'vue'
import { Prop, Watch } from 'vue-property-decorator'

interface ITabs {
    name: string
    value: string
}

export default class extends Vue {
    @Prop({
        type: Array,
        default() {
            return []
        }
    })
    public tabs!: ITabs[] // TS2416
}

TS2416: Property 'tabs' in type 'default' is not assignable to the same property in base type 'object & Record & Vue'. Type 'ITabs[]' is not assignable totype '{ name: ""; value: ""; }[] | undefined'. Type 'ITabs[]' is not assignable to type '{ name: ""; value: ""; }[]'. Type 'ITabs' is not assignable to type '{ name: ""; value: ""; }'. Types of property 'name' are incompatible. Type 'string' is not assignable to type '""'.

I want to use interface in the Prop Array, what do I do?

1 Answer 1

3

In case anyone struggles with it like I did, this is what worked for me:

@Prop({ default: () => {
        return [ ]
    }
    }) private tabs!: ITabs[];
Sign up to request clarification or add additional context in comments.

1 Comment

This works like a charm! Really appreciate it but now I'm wondering why this usage works...

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.