question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't make type check for props work for global components with volar

See original GitHub issue

Demo project

Hi! I’ve created a fresh vite app with this plugin, added globalComponentsDeclaration: true. The file components.d.ts is generated, but vscode doesn’t show me warnings of incorrect using of props, unless I import the component.

Button.vue:

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

const props = defineProps({
  size: {
    type: String,
    required: true,
  },
})
</script>

Component is not imported (no type checks for props) Screen Shot 2021-05-31 at 20 26 19

Component is imported, so type check works great. Screen Shot 2021-05-31 at 20 27 13

I’m expecting to see something like that: https://twitter.com/antfu7/status/1397168229005463563 but can’t figure out what’s wrong.

And what’s more strange, this feature is working perfectly if I install a new vitesse project.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
xorikcommented, Jun 1, 2021

@antfu found the issue: By default vite have tsconfig.json:

  "include": [
    "src/**/*.ts",
    "src/**/*.d.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
  ]

So file components.d.ts is not included. Vitesse in the other hand doesn’t have include, only exclude in the config.

Probably it makes sense to add it to readme, so other people won’t get confused.

0reactions
xorikcommented, Jun 1, 2021

Yes, plugin is on. I will try to compare libraries between this and vitesse, probably some package is messing with type definitions. https://user-images.githubusercontent.com/347044/120286326-68a2b300-c2be-11eb-8639-eab9dc08501a.mov

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot correctly infer type for $slots of global components #953
This is expected behavior, $slots type is from DefineComponent but not define by volar. You can not inherit parent slots type by this...
Read more >
How can I make Volar aware of globally available components ...
Global components should be declared in src/components.d.ts : import { CAlert } from '@coreui/vue' declare module '@vue/runtime-core' ...
Read more >
Using Vue with TypeScript - Vue.js
If using SFCs, use the vue-tsc utility for command line type checking and type ... To get Vue SFCs and TypeScript working together,...
Read more >
volar/vue-typescript - NPM Package Versions - Socket.dev
Start using Socket to analyze @volar/vue-typescript and its 3 ... fix: props type checking not working for Element Plus components (#2176) (#2180) ...
Read more >
Vue with TSX - the perfect duo!? - Arek Nawo
It's a (mostly) TS-only library of types, casting function, utilities, etc., meant to properly type your Vue components and make them work ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found