Components that only use `defineProps`, don't export type information
After upgrading to nuxt
3.17.5
from 3.16.1
, I'm getting type errors from components that use defineProps
, without also using defineEmits
or defineModel
.
For example this component:
Will give this error:
The error goes away if I update my component like so:
The type of my component is now correctly set as:
Using defineEmits
instead of defineModel
also seems to work.
Output of npx nuxi info
:
I can't reproduce it in a minimal repo. Has anyone had similar issues and what steps could I take to debug this?4 Replies
Hi @Mike. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
I'm sorry, but the knowledge sources do not explicitly mention the specific issue where components using only defineProps in Nuxt 3.17.5 fail to export type information, resulting in type errors unless defineModel or defineEmits is also used.
However, there are related discussions about type checking and TypeScript support in Nuxt 3. For example, using TypeScript with <script setup lang="ts"> and defineProps is the recommended approach for strong typing in components, and omitting lang="ts" can cause type errors in VS Code and Volar, but this does not directly address your issue with type inference and component types after upgrading Nuxt versions Vue with Nuxt TypeScript Support, Stack Overflow: Getting intellisense errors.
There are also reports of type checking issues in SFC templates depending on project structure or after upgrades, which were resolved by updating dependencies or deduping packages, but again, these do not match your exact scenario No type check in SFC templates if components directory is empty, Manually typing App Config doesn't work.
Given that you cannot reproduce the issue in a minimal repo, it may be related to your project's specific configuration, dependency versions, or possibly a cache or lockfile issue. Some users have resolved similar upgrade-related type issues by running:
and ensuring all related dependencies (like @nuxt/kit, @nuxt/types, and Volar) are up to date and compatible with your Nuxt version.
If the problem persists, consider:
- Deleting node_modules and your lockfile, then reinstalling dependencies.
- Checking for any custom TypeScript or Volar configuration that might affect type inference.
- Ensuring you are using <script setup lang="ts"> in all relevant components.
If you continue to experience this issue, you may want to open a new issue on the Nuxt GitHub repository with a reproduction if possible, as this may be a regression or edge case not yet documented in the knowledge sources.
Again, I'm sorry I couldn't find a direct answer to your specific problem in the provided sources.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@118401999526952967> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Tried all of the above
Turns out it was a bug in the vue-tsc compiler: https://github.com/vuejs/language-tools/issues/5452
GitHub
Props are not inferred when using
fallthroughAttributes
and multi...Vue - Official extension or vue-tsc version vue-tsc 2.2.10 VSCode version N/A Vue version 3.5.17 TypeScript version 5.8.0 System Info System: OS: macOS 15.5 CPU: (10) arm64 Apple M4 Memory: 336.75 ...