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

Typescript - 'Cannot find name ____' when annotating props with interface #2857

Closed
4 tasks done
sergmister opened this issue Apr 10, 2021 · 2 comments
Closed
4 tasks done

Comments

@sergmister
Copy link

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ
  • I have tried restarting VS Code or running Vetur: Restart VLS

Info

  • Platform: Linux
  • Vetur version: 0.33.1
  • VS Code version: 1.55.1

Problem

When I use an interface to annotate props Vetur gives give the error 'Cannot find name 'Foo'. Vetur(2304)'.

Reproducible Case

This setup works perfectly fine:
Test.vue

<script lang="ts">
import { defineComponent, PropType } from "vue";

export interface Foo {
  name: string;
}

export default defineComponent({
  props: {
    foo: { type: Object as PropType<{ name: string }> },
  },
});
</script>

App.vue

<template>
  <p>hi</p>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import Test from "@/test.vue";

export default defineComponent({
  components: { Test },
});
</script>

However, when I change props in Test.vue to

  props: {
    foo: { type: Object as PropType<Foo> },
  },

Vetur give the error 'Cannot find name 'Foo'. Vetur(2304)' at the top of App.vue. The code runs just fine in Vue.

@HayasyLL
Copy link

same issue when pass props as PropType

in child component
image

in parent component, pass object to child component
image

first line of parent component
image

@yoyo930021
Copy link
Member

Duplicate of #2668

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

No branches or pull requests

3 participants