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 with slots don't work with Vue 2.7 #3241

Closed
ferm10n opened this issue May 31, 2023 · 1 comment
Closed

Generics with slots don't work with Vue 2.7 #3241

ferm10n opened this issue May 31, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@ferm10n
Copy link

ferm10n commented May 31, 2023

It looks like a generic can be defined, but type argument doesn't appear in the slot. Instead it appears as the generic type.

Example of this working correctly with Vue 3:

<Foo :items="items">
<template #content="{ item }">
<div>{{ item.name }}</div>
</template>
</Foo>

Here, Foo has a generic T extends { index: number }:

<script setup lang="ts" generic="T extends {index: number}">

However, trying this with Vue 2.7 fails:
image

Reproduction

  • starting from cloning this repo @ develop, pnpm install --frozen-lockfile and pnpm build
  • from within packages/vue-test-workspace...
    • edit tsconfig.json to only target the failing test
{
        // ...
	"include": [
		"vue-tsc/#2639/*"
	]
}
  • confirm the test is good so far with vue 3: node ../vue-tsc/bin/vue-tsc.js --noEmit
  • edit packages/vue-test-workspace/package.json to use vue 2.7 and pnpm install
  • running vue-tsc.js again produces this error:
vue-tsc/#2639/Bar.vue:4:17 - error TS2339: Property 'name' does not exist on type '{ index: number; }'.

4    <div>{{ item.name }}</div>
                  ~~~~


Found 1 error in vue-tsc/#2639/Bar.vue:4

Some extra thoughts...

I'd really like to help with this project more, but it's difficult to know where to begin and it's challenging learning how all the packages in this repo work together to perform type checking.

I'm super thankful for this extension, IMO there aren't any viable alternatives for Vue 2.7 anymore. Volar seems to be the way to go, but maybe it'd be helpful to create another test package just like vue-test-workspace, but have it use vue 2.7 instead of vue 3. I'd imagine it'd have a subset of the tests from vue-test-workspace, for covering the stuff that should be possible with vue 2.7 and vue 3.

I tried creating this setup and could make a PR for it, but I could use some guidance figuring out which tests should apply to both 2 and 3. However, I wanted to know if that's even desirable for this repo before putting more effort into it. Any thoughts?

@so1ve
Copy link
Member

so1ve commented Nov 16, 2023

Should work now

@johnsoncodehk johnsoncodehk added the bug Something isn't working label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants