Skip to content

Adding generic= to <script setup> makes it impossible to export types from SFC #13410

Open
@alexchexes

Description

@alexchexes

Vue version

3.5.16

Link to minimal reproduction

https://github.com/alexchexes/vue-test-generic-export/blob/master/src/App.vue

Steps to reproduce

  1. Add generic="T" attribute to the <script setup> (<script setup lang="ts" generic="T">)
  2. Add a type export, e.g. export type MyType = 123, within that script setup scope
  3. Observe the Modifiers cannot appear here. ts(1184) TypeScript error in VSCode
  4. Remove generic="T" and the error disappears, confirming the issue is related to the generic="T" attribute

Reproduction:

<script setup lang="ts" generic="T">
defineProps<{
  items: string[]
  selected: string
}>()
export type MyType = 123 // ← TS Error: Modifiers cannot appear here. ts(1184)
</script>

What is expected?

No error should occur when exporting types after adding generic="T" to <script setup>

What is actually happening?

A Modifiers cannot appear here. ts(1184) TypeScript error appears as soon as generic="T" is added to <script setup>, but no error occurs when it is removed

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700H
    Memory: 32.97 GB / 63.67 GB
  Binaries:
    Node: 22.11.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.9.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.12.3 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Edge: Chromium (130.0.2849.80)
  npmPackages:
    vue: ^3.5.13 => 3.5.16

Any additional comments?

If this is a restriction of generic components, we should mention it in the generics section of the <script setup> docs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions