Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Vue 2.7] Type of annotated prop not recognized in the component #2347

Closed
rchl opened this issue Jan 30, 2023 · 3 comments
Closed

[Vue 2.7] Type of annotated prop not recognized in the component #2347

rchl opened this issue Jan 30, 2023 · 3 comments
Labels

Comments

@rchl
Copy link
Collaborator

rchl commented Jan 30, 2023

Repro:

Repository: https://github.com/rchl/volar-vue2-test (pages/typeless.vue file)

<template>
    <div>noop</div>
</template>

<script>
export default {
    props: {
        tracks: {
            /** @type {import('vue').PropType<MyNamespace.Track[]>} */
            type: Array,
            required: true,
        },
    },
    data() {
        return {
            inputs: this.tracks.map(track => track),
        };
    },
};
</script>
declare namespace MyNamespace {
    type Track = {
        id: number;
        title: string;
    };
}

Expected

The type of this.tracks is correctly reported as Track[]

Actual

Screenshot 2023-01-30 at 23 10 41

@rchl
Copy link
Collaborator Author

rchl commented Jan 30, 2023

I guess the example is needlessly complicated. It could even not have any JSDoc annotation probably and would still reproduce.

@rchl
Copy link
Collaborator Author

rchl commented Jan 30, 2023

Or is it about JSDoc just not working in this context?

This TS file seems to work:

import { defineComponent, PropType } from 'vue'

export default defineComponent({
    props: {
        tracks: {
            type: Array as PropType<string[]>,
            required: true,
        },
    },
    data() {
        return {
            inputs: this.tracks.map(track => track),
        };
    },
})

but not this JS file:

import { defineComponent } from 'vue'

export default defineComponent({
    props: {
        tracks: {
            /** @type {import('vue').PropType<string[]>} */
            type: Array,
            required: true,
        },
    },
    data() {
        return {
            inputs: this.tracks.map(track => track),
        };
    },
})

@zcf0508
Copy link
Contributor

zcf0508 commented Aug 5, 2023

vuejs/vue#13063

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

No branches or pull requests

3 participants