Skip to content

Global types as generic type parameter in defineProps causing an exception #29757

Closed

Description

@cewald

Environment

  • Operating System: Linux
  • Node Version: v20.9.0
  • Nuxt Version: 3.13.2
  • CLI Version: 3.15.0
  • Nitro Version: 2.9.7
  • Package Manager: [email protected]
  • Builder: -
  • User Config: default
  • Runtime Modules: -
  • Build Modules: -

Reproduction

You can add any global accessible type or interface into a defineProps generic type parameter like defineProps<GlobalType> and it will drop the exception: ERROR Pre-transform error: [@vue/compiler-sfc] Unresolvable type reference or unsupported built-in utility type.

I've created a minimal setup in a CodeSandbox where the problem is visible and reproducible:
https://codesandbox.io/p/devbox/sweet-cdn-hgtnpd

Describe the bug

I have a nuxt-module that inserts global types using addTypeTemplate. The types are generated and linked correctly in the .nuxt/nuxt.d.ts and put in the ./nuxt/types/ folder. I can include those types and interfaces everywhere I want in my IDE (VSCode) and Typescript is recognizing the new global imports.

But when I use one of this global imports, like a type or an interface as a generic type parameter in the defineProps method of a component like defineProps<MyCustomGlobalType>() I get the following exception in the browser and from the vite server:

ERROR  Pre-transform error: [@vue/compiler-sfc] Unresolvable type reference or unsupported built-in utility type

/project/workspace/components/TestComponent1.vue
1  |  <script setup lang="ts">
2  |  defineProps<TestComponentProps>()
   |              ^^^^^^^^^^^^^^^^^^
3  |  </script>

Additional context

The funny thing is, that the global imports work if I do not use them as a root generic type parameter – it works even if I use the prop as nested props in the generic-type prop of defineProps but not as root (see TestComponent2.vue). I've made several examples in the CodeSandbox: components/TestComponent1.vue drops the exception and the other 2 components show that the rest is working fine.

It is also not related to the type-generation of my module, I have also tried generic global types of Nuxt and it drops the same error.

I have tried a lot, but wasn't able to fix it myself – any help is appreciated.

Logs

No response

Activity

  1. added
    upstream
    on Nov 2, 2024
  2. danielroe commented on Nov 2, 2024

    @danielroe
    Member

    this is likely stemming from a limitation of vue/compiler

  3. danielroe commented on Nov 4, 2024

    @danielroe
    Member

    Would you see if you can reproduce this in pure Vue SSR without Nuxt (reproduction sandbox), and if so, raise there? 🙏

  4. cewald commented on Nov 5, 2024

    @cewald
    Author

    I'll do asap :) thanks for the hint already

  5. lessainspasorchies commented on Nov 17, 2024

    @lessainspasorchies

    I have the same problem with a bare Nuxt 3.14.159 app on Stackblitz.
    I have a few types globally available in a global.d.ts file within @@/types :

    export { };
    
    declare global {
        interface A {
        }
        
        interface B {
        }
    }
    

    Type check and inference works in Nitro:
    Image

    None works in app.vue or components, Nuxt 3 style or with the /app folder when future: { compatibilityVersion: 4 } is set in nuxt.config.ts. (I'm hovering aboutData in the ContentSection component/v-for, nothing )
    Image

    This is the error I get:

    ERROR  Pre-transform error: [@vue/compiler-sfc] Unresolvable type reference or unsupported built-in utility type                                                               4:09:24 PM
    
    /Users/tdilenarda/Code/Tests/nuxt3-test/components/ContentSection.vue
    1  |  <script lang="ts" setup>
    2  |  const props = defineProps<AboutSection>();
      |                            ^^^^^^^^^^^^
    3  |  </script>
    4  |  
    

    despite having a 200 when going to http://localhost:3000/api/about with the right and whole data.

    The component that causes the crash:
    Image

    Seems Vue is in fault here.
    I reopened an old Nuxt project (in 3.12.4 with Vue 3.4.37) and everything works as it should!

  6. lessainspasorchies commented on Nov 23, 2024

    @lessainspasorchies

    I found a workaround by changing

    defineProps<AboutSection>();
    

    with

    defineProps<{
      section: AboutSection;
    }>();
    

    Error is gone with the latest Vue release (3.5.13)

  7. zulfm commented on Aug 16, 2025

    @zulfm

    I found a workaround by changing

    defineProps<AboutSection>();
    

    with

    defineProps<{
      section: AboutSection;
    }>();
    

    Error is gone with the latest Vue release (3.5.13)

    I already tried it and i works. But i don't want that pattern
    i want to achieve:

    <MyButton variant="ghost" />
    

    not the:

    <MyButton :props="{ variant: 'ghost' }" />
    

    Its very frustrating, help.

  8. danielroe commented on Aug 21, 2025

    @danielroe
    Member

    There are two pieces here. First, you need to change the format of your declaration:

      declare global {
    -   export type TestComponentProps = {
    +   type TestComponentProps = {
          foo: string;
          bar: number;
        };
      }
      
      export {};

    Having said that, I've now raised #33026 to resolve the issue,

    If you need to work around it in the mean time,, you need to make sure your type template is present in the Vue global type files:

    import { resolve } from 'node:path'
    
    export default defineNuxtConfig({
      vite: {
        vue: {
          script: {
            globalTypeFiles: [
              resolve('.nuxt/types/sampleModule.base.d.ts'),
            ]
          }
        }
      }
    })
  9. userquin commented on Aug 21, 2025

    @userquin
    Member

    Will check adding pwa icons types to vue, this was working with v3.* without any hack, moving .vue to .ts + defineComponent is working fine

  10. Tenrys commented on Sep 4, 2025

    @Tenrys

    Using v4.1.0, still having this issue:

    // app/utils/types/props/index.d.ts
    
    import type { QDateProps, QTimeProps } from 'quasar'
    import type { HInputProps } from '~/plugins/quasar-component-extensions'
    
    declare global {
    	// ...
    
    	type DateRange = { from: string; to: string }
    	type DateInputProps = {
    		modelValue?: DateRange | string | null
    		dateProps?: Omit<Partial<QDateProps>, 'mask'>
    		timeProps?: Omit<Partial<QTimeProps>, 'mask'>
    		hasDate?: boolean
    		hasTime?: boolean
    		clearable?: boolean
    		/** https://day.js.org/docs/en/display/format */
    		mask: string
    		disable?: boolean
    		// parentProps?: Partial<HInputProps>;
    	} & Partial<HInputProps>
    }
    
    export {}
    Image

    Though I just checked the reproduction, do you really need to have a module for this to work?

    Prior to v4.1.0, I just had the above file, but as a normal TypeScript file, without declare global, exporting every type, which worked just fine, if I imported them in my relevant components from #imports. However this doesn't seem to work anymore, unless I just import straight from the file my props types are defined from.

  11. Matheun commented on Oct 28, 2025

    @Matheun

    Still having this issue in nuxt v4.2

  12. ThomasBerneHCSE commented on Dec 4, 2025

    @ThomasBerneHCSE

    @danielroe Hi, it seems like we still have the issue. Without adding the type import the auto imported type shows an error. Any idea why this is still present?

  13. 7by24 commented on Dec 18, 2025

    @7by24

    Still having this issue in nuxt v4.2

  14. develth commented on Dec 18, 2025

    @develth

    on a fresh installed nuxt it works for me.
    i just upgraded another project to latest version -> same error

     [@vue/compiler-sfc] Unresolvable type reference or unsupported built-in utility type [..] | import type { TopType } from '#imports'
    

    btw. build and run of app works, just in dev mode

  15. jjkuga commented on Jul 28, 2026

    @jjkuga

    I encountered the same issue with Nuxt 4.5.1. In my case, I worked around it by downgrading the TypeScript version.

    Environment

    • Nuxt: 4.5.1
    • pnpm (single version of @vue/compiler-sfc confirmed via pnpm why)

    Reproduction

    • Occurs when a component uses defineProps<T>() with T imported via import type from an external file, whether using an alias or a relative path.
    • Currently, Reproduces in a freshly created Nuxt project (not specific to project config/aliases).

    Suspected the root cause was a TypeScript version compatibility issue

    • TypeScript 6.0.3 → works correctly
    • TypeScript 7.0.2 → error occurs
    • A plain Vue (non-Nuxt) project with the same TypeScript 7.0.2 does not reproduce the error.

    Workaround

    Pinning TypeScript to 6.x resolves the issue:

    {
      "dependencies": {
        "nuxt": "^4.5.1",
        "vue": "^3.5.40"
      },
      "devDependencies": {
        "typescript": "^6.0.3"
      }
    }
  16. added theissue type on Aug 2, 2026
  17. danielroe commented on Sep 2, 2026

    @danielroe
    Member

    this was resolved in #33026 (v3.19 or v4.1)

    typescript v7 does not yet work with vue - they are working on this.

    if you encounter something like this again, please open a new issue 🙏

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending triagepossible regressionupstream

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions