Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generics Inferencing Breaks with & extended objects #5159

Open
crutchcorn opened this issue Feb 1, 2025 · 1 comment
Open

Generics Inferencing Breaks with & extended objects #5159

crutchcorn opened this issue Feb 1, 2025 · 1 comment
Labels
good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first 🔩 p2-edge-case

Comments

@crutchcorn
Copy link

Vue - Official extension or vue-tsc version

2.2.0

VSCode version

1.96.4

Vue version

3.5.13

TypeScript version

5.7.3

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (24) x64 AMD Ryzen AI 9 HX 370 w/ Radeon 890M
    Memory: 31.40 GB / 59.62 GB
  Binaries:
    Node: 20.18.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - C:\Program Files\nodejs\yarn.CMD
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.14.4 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (131.0.2903.112)

package.json dependencies

"dependencies": {
	"vue": "^3.5.13"
},
"devDependencies": {
	"@vitejs/plugin-vue": "^5.2.1",
	"typescript": "^5.7.3",
	"vite": "^6.0.11"
}

Steps to reproduce

If you set up a generic component with a type-cast like so:

<!-- Header.vue -->
<script setup lang="ts" generic="T extends keyof HTMLElementTagNameMap = 'h1'">
type Props = Partial<HTMLElementTagNameMap[T]> & {
	as?: T;
}

const props = defineProps<Props>();

const Component = props.as || "h1";
</script>

<template>
	<component :is="Component" v-bind="props" style="color: darkred">
		<slot />
	</component>
</template>

Then try to use it:

<!-- App.vue -->
<script setup lang="ts">
import Header from "./Header.vue";
</script>

<template>
  <Header as="h2">
    Testing
  </Header>
</template>

The as="h2" will warn you:

Type '"h2"' is not assignable to type '"h1"'.ts-plugin(2322)

What is expected?

No type error

What is actually happening?

A type error is given

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-aflytz5e?file=src%2Fmain.js,src%2FHeader.vue&terminal=dev

Any additional comments?

This also happens with the following syntax:

<!-- Header.vue -->
<script setup lang="ts" generic="T extends keyof HTMLElementTagNameMap = 'h1'">
const props = defineProps<
  Partial<HTMLElementTagNameMap[T]> & {
    as?: T;
  }
>();

const Component = props.as || 'h1';
</script>

<template>
  <component :is="Component" v-bind="props" style="color: darkred">
    <slot />
  </component>
</template>
@KazariEX KazariEX added good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first 🔩 p2-edge-case and removed pending triage labels Feb 2, 2025
@KazariEX
Copy link
Member

KazariEX commented Feb 2, 2025

It is caused by Prettify.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first 🔩 p2-edge-case
Projects
None yet
Development

No branches or pull requests

2 participants