Skip to content

"script setup" syntax has problems with importing types #132

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

Closed
chojnicki opened this issue Apr 9, 2021 · 3 comments
Closed

"script setup" syntax has problems with importing types #132

chojnicki opened this issue Apr 9, 2021 · 3 comments
Labels
question Further information is requested

Comments

@chojnicki
Copy link

Actually I'm not sure if this is more Vue 3 or Volar issue.

While importing "PropType" I'm getting warnings in IDE:

'PropType' only refers to a type, but is being used as a value here. ts(2693)

Code for reproduction:

<script setup lang="ts">
import { defineProps, PropType } from 'vue'

defineProps({
  demo: {
    type: Object as PropType<{ demo: string }>,
    required: true,
  },
})
</script>

Thing is, it looks fine without setup syntax.

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

export default defineComponent({
  props: {
    demo: {
      type: Object as PropType<{ demo: string }>,
      required: true,
    },
  }
})
</script>

Same thing happens for me while importing any custom types/interfaces.

import { SomeType } from '@/types/sometypes'

But I found out that warning also disappears after using "import type"

import type { SomeType } from '@/types/sometypes'

Cool, so accordingly we can also do this:

import { defineComponent } from 'vue'
import type { PropType } from 'vue'

But this shouldn't be necessary. I also did not found this in any vue docs or RFC. So why this TS warning appears with script setup?

Have a nice day :)

@johnsoncodehk
Copy link
Member

Hi @chojnicki, this is vue limitation, see: vuejs/core#3183

So I create this error to avoid user runtime error.

@johnsoncodehk johnsoncodehk added the question Further information is requested label Apr 9, 2021
@chojnicki
Copy link
Author

Instant reply as always, are you resting at all? 😆

Thanks for linking issue, I will stick with import type then.

@johnsoncodehk
Copy link
Member

I want to finish this project as soon, and then I can rest. 😅

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

No branches or pull requests

2 participants