Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Cannot use @Prop() Decorator #250

Open
smholsen opened this issue Aug 26, 2019 · 7 comments
Open

Cannot use @Prop() Decorator #250

smholsen opened this issue Aug 26, 2019 · 7 comments

Comments

@smholsen
Copy link

Hi,
I am in the midst of trying to rewrite my hobby project from js to ts, and I am currently trying to use the @prop decorator in my component using the code below;

<template>
...
</template>
<script lang="ts">

    import Vue from "vue";
    import Component from "vue-class-component";
    import {Prop} from "vue-property-decorator";

    @Component({
        name: "Additional"
    })

    export default class Additional extends Vue {
        notes: string = '';

        @Prop() value: any;
 }
</script>

But I get the following error in my IDE;

Argument of type 'Additional' is not assignable to parameter of type 'Vue'.
  Types of property '$options' are incompatible.
    Type 'Vue.ComponentOptions<import("/{...}/node_modules/vue/types/vue").Vue, import("/{...}/node_modules/vue/types/options").DefaultData<import("/{...}/node_modules/vue/types/vue").Vue>, import("/Users/{username}/proj...' is not assignable to type 'import("/{...}/node_modules/vue-property-decorator/node_modules/vue/types/options").ComponentOptions<import("/{...}/node_modules/vue-property-decorator/node_modules/vue/types/vue").Vue, import("/{...}/node_...'.
      Types of property 'methods' are incompatible.
        Type 'import("/{...}/node_modules/vue/types/options").DefaultMethods<import("/{...}/node_modules/vue/types/vue").Vue> | undefined' is not assignable to type 'import("/{...}/node_modules/vue-property-decorator/node_modules/vue/types/options").DefaultMethods<import("/{...}/node_modules/vue-property-decorator/node_modules/vue/types/vue").Vue> | undefined'.
          Type 'import("/{...}/node_modules/vue/types/options").DefaultMethods<import("/{...}/node_modules/vue/types/vue").Vue>' is not assignable to type 'import("/{...}/node_modules/vue-property-decorator/node_modules/vue/types/options").DefaultMethods<import("/{...}/node_modules/vue-property-decorator/node_modules/vue/types/vue").Vue>'.
            Index signatures are incompatible.
              Type '(this: import("/{...}/node_modules/vue/types/vue").Vue, ...args: any[]) => any' is not assignable to type '(this: import("/{...}/node_modules/vue-property-decorator/node_modules/vue/types/vue").Vue, ...args: any[]) => any'.
                The 'this' types of each signature are incompatible.
                  Type 'Vue' is missing the following properties from type 'Vue': $router, $route, $storeVetur(2345)

Do you have any suggestions or ideas on what is going wrong here?
Any tips on where to start debugging this issue?

@asbermudez
Copy link
Contributor

@smholsen This PR solves the issue...
#246

I hope that @kaorun343 checks it soon

@smholsen
Copy link
Author

smholsen commented Aug 26, 2019 via email

@asbermudez
Copy link
Contributor

asbermudez commented Aug 26, 2019 via email

@smholsen
Copy link
Author

Thanks!

That probably works, but for IDE support it's not ideal, as my IDE does not recognize the props defined in the @component deocrator in the class.

E.g. See this example;

    @Component({
        name: "Additional",
        props: {
            notes: String,
        }
    })

    export default class Additional extends Vue {
        doSomething() {
            // this.notes is not recognized by the IDE
            this.notes = '';
        }
    }

Is there anyway to work around this? Would it work fine to define the prop in the class like this for example?

    @Component({
        name: "Additional",
        props: {
            notes: String,
        }
    })

    export default class Additional extends Vue {
        notes!: string;
        doSomething() {
            // Now this.notes is recognized by the IDE
            this.notes = '';
        }
}

Is there any problems with this approach? Is any other solution better?

@asbermudez
Copy link
Contributor

asbermudez commented Aug 26, 2019 via email

@kaorun343
Copy link
Owner

Please check the latest version, v8.2.2 .

@niklaspalm
Copy link

Hey, this is how I usually get around this problem:

<template>
...
</template>
<script lang="ts">

    import { Component, Vue } from "vue-property-decorator";

    const AppProps = Vue.extend({
        props: {
            notes: {
                type: String
            }
        }
    })

    @Component({
        name: "Additional"
    })

    export default class Additional extends AppProps {
        doSomething() {
            this.notes = '';
        }
    }
</script>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants