Skip to content

Generics with default value narrows union to default #6185

Description

@ludwig801

Vue - Official extension or vue-tsc version

3.3.11

VSCode version

1.127.0

Vue version

3.5.27

TypeScript version

5.9.3

Steps to reproduce

Create a simple sfc file with a generic declaration.
Notice the default value for TUnion, which is the important part.

<template>
  <span>Not important for the example</span>
</template>

<script setup lang="ts" generic="TUnion extends 'a' | 'b' = 'a'">
const { union = 'a' } defineProps<{ union: TUnion }>()
</script>

What is expected?

When using the component, it is expected that vscode would suggest 'a' or 'b' as valid values for the union prop when autocompleting.

What is actually happening?

When using the component, it only suggests the default 'a' for the prop.

Link to minimal reproduction

No response

Any additional comments?

I think it is important to mention that it no longer happens using Typescript 6.x.x.
I haven't updated my project to TS 6.x.x because of some other issues.
If you tell me that this is due to a TS limitation and not due to any internal issue, please disregard this bug.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions