N
Nuxt3mo ago
Mike

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:
<script setup lang="ts">
defineProps<{ status: "running" | "paused" }>();
</script>
<template>
<p>{{ status }}</p>
</template>
<script setup lang="ts">
defineProps<{ status: "running" | "paused" }>();
</script>
<template>
<p>{{ status }}</p>
</template>
Will give this error:
Object literal may only specify known properties, and 'status' does not exist in type 'Partial<{}> & Omit<{} & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.
Object literal may only specify known properties, and 'status' does not exist in type 'Partial<{}> & Omit<{} & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'.
The error goes away if I update my component like so:
<script setup lang="ts">
defineProps<{ status: "running" | "paused" }>();
defineModel<boolean>() // added this
</script>
<template>
<p>{{ status }}</p>
</template>
<script setup lang="ts">
defineProps<{ status: "running" | "paused" }>();
defineModel<boolean>() // added this
</script>
<template>
<p>{{ status }}</p>
</template>
The type of my component is now correctly set as:
{
readonly status: "running" | "completed" | "draft" | "sending" | "paused";
readonly modelValue?: boolean | undefined;
readonly "onUpdate:modelValue"?: ((value: boolean | undefined) => any) | undefined;
} & VNodeProps & AllowedComponentProps & ComponentCustomProps
{
readonly status: "running" | "completed" | "draft" | "sending" | "paused";
readonly modelValue?: boolean | undefined;
readonly "onUpdate:modelValue"?: ((value: boolean | undefined) => any) | undefined;
} & VNodeProps & AllowedComponentProps & ComponentCustomProps
Using defineEmits instead of defineModel also seems to work. Output of npx nuxi info:
- Operating System: `Darwin`
- Node Version: `v22.10.0`
- Nuxt Version: `3.17.5`
- CLI Version: `3.25.1`
- Nitro Version: `2.11.12`
- Package Manager: `pnpm@10.12.1`
- Builder: `-`
- User Config: `devtools`, `extends`, `devServer`, `css`, `modules`, `ssr`, `vite`, `i18n`, `runtimeConfig`, `compatibilityDate`, `routeRules`, `experimental`, `ignore`, `sentry`, `sourcemap`
- Runtime Modules: `@nuxtjs/i18n@9.4.0`, `@nuxt/eslint@0.7.6`, `@sentry/nuxt/module@8.43.0`, `motion-v/nuxt@0.10.0`, `@nuxt/test-utils/module@3.19.1`
- Build Modules: `-`
- Operating System: `Darwin`
- Node Version: `v22.10.0`
- Nuxt Version: `3.17.5`
- CLI Version: `3.25.1`
- Nitro Version: `2.11.12`
- Package Manager: `pnpm@10.12.1`
- Builder: `-`
- User Config: `devtools`, `extends`, `devServer`, `css`, `modules`, `ssr`, `vite`, `i18n`, `runtimeConfig`, `compatibilityDate`, `routeRules`, `experimental`, `ignore`, `sentry`, `sourcemap`
- Runtime Modules: `@nuxtjs/i18n@9.4.0`, `@nuxt/eslint@0.7.6`, `@sentry/nuxt/module@8.43.0`, `motion-v/nuxt@0.10.0`, `@nuxt/test-utils/module@3.19.1`
- Build Modules: `-`
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
kapa.ai
kapa.ai3mo ago
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:
npx nuxt@latest upgrade --dedupe
npx nuxt@latest upgrade --dedupe
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: ----------------------
kapa.ai
kapa.ai3mo ago
<@118401999526952967> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Mike
MikeOP3mo ago
Tried all of the above
Mike
MikeOP3mo ago
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 ...

Did you find this page helpful?