Vue: Typescript: Property 'foo' does not exist on type 'Vue'.

Created on 15 Oct 2018  ·  9Comments  ·  Source: vuejs/vue

Version

2.5.17

Reproduction link

https://stackblitz.com/edit/typescript-bc9ywj

Steps to reproduce

  1. open index.ts, you will see:

image

  1. change x: [String, Number, Array] to x: [String, Number], then errors disappear:

image

What is expected?

no typing errors.

What is actually happening?

typing errors exist.

Most helpful comment

export default Vue.extend({
    name: 'WebWhatsNew',
    data() {
        return {
            currentSlide: 0 as number
        };
    },
    methods: {
        nextSlide() {
            this.currentSlide += 1;
        },
    },
    computed: {
        internalOpen: {
            get(): boolean {
                return this.value;
            },
            set(val) {
                (this as any).$emit('input', false);
            },
        },
    },
});

I get this typing error with the code above.
image

When I remove

            set(val) {
                (this as any).$emit('input', false);
            },

then the compile error is gone.

Edit: I fixed the issue by set(val: boolean), adding type to val.

It's my mistake not to add type to val but the lint should give the proper error. However it fixes automatically when you try to fix the other typing issues.

Hope it helps anyone who hits the similar issue.

All 9 comments

Check https://vuejs.org/v2/guide/typescript.html


Please, next time consider using the forum, the Discord server or StackOverflow for questions first. But feel free to come back and open an issue if it turns out to be a bug 🙂

@posva i know, but i think this is a bug.

@ktsn can you help me check if this is a bug? thx~

emm, this is not a bug. this will be ok:

x: [String, Number, Array as () => Array<string | number>]

I am experiencing the exact same issue. @fjc0k Can you please point me way out?

@ITsolution-git Sorry, I haven't used vue for a long time. Now, I prefer react, which works better with typescript.

export default Vue.extend({
    name: 'WebWhatsNew',
    data() {
        return {
            currentSlide: 0 as number
        };
    },
    methods: {
        nextSlide() {
            this.currentSlide += 1;
        },
    },
    computed: {
        internalOpen: {
            get(): boolean {
                return this.value;
            },
            set(val) {
                (this as any).$emit('input', false);
            },
        },
    },
});

I get this typing error with the code above.
image

When I remove

            set(val) {
                (this as any).$emit('input', false);
            },

then the compile error is gone.

Can anyone help

export default Vue.extend({
    name: 'WebWhatsNew',
    data() {
        return {
            currentSlide: 0 as number
        };
    },
    methods: {
        nextSlide() {
            this.currentSlide += 1;
        },
    },
    computed: {
        internalOpen: {
            get(): boolean {
                return this.value;
            },
            set(val) {
                (this as any).$emit('input', false);
            },
        },
    },
});

I get this typing error with the code above.
image

When I remove

            set(val) {
                (this as any).$emit('input', false);
            },

then the compile error is gone.

Edit: I fixed the issue by set(val: boolean), adding type to val.

It's my mistake not to add type to val but the lint should give the proper error. However it fixes automatically when you try to fix the other typing issues.

Hope it helps anyone who hits the similar issue.

I have this problem too. Was banging my head on the wall until I read this thread

+1

Was this page helpful?
0 / 5 - 0 ratings