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

Dynamic slot name Template error: Type 'QTableSlots' has no matching index signature for type 'string'.ts-plugin(2537) #4668

Closed
tomvdk opened this issue Aug 8, 2024 · 6 comments · Fixed by #4669
Assignees
Labels
bug Something isn't working 🔨 p3-minor-bug

Comments

@tomvdk
Copy link

tomvdk commented Aug 8, 2024

Vue - Official extension or vue-tsc version

2.0.28

VSCode version

1.91.1

Vue version

3.4.29

TypeScript version

5.4.5

System Info

No response

Steps to reproduce

As of version 2.0.28 of Vue Official, we get the following syntax highlighting if we use a dynamic slot name. In this case it is for QTableSlots of the Quasar Component Library.

<template #[`body-cell-${actionsKey}`]="data">

image

What is expected?

No syntax highlighting as described in https://vuejs.org/guide/components/slots.html#dynamic-slot-names

What is actually happening?

Syntax highlighting and error in Problems window. When using Vue Official 2.0.26 this error does not occur.

Link to minimal reproduction

No response

Any additional comments?

No response

@davidmatter davidmatter added bug Something isn't working 🔨 p3-minor-bug and removed pending triage labels Aug 8, 2024
@davidmatter
Copy link
Collaborator

Regression from #4478

Test case

main.vue

<template>
  <Child>
    <template #[`action${n}`]="data">
      {{ exactType(data.a, {} as string) }}
    </template>
    <template #[`action2`]="data">
      {{ exactType(data.a, {} as string) }}
    </template>
  </Child>
</template>
<script lang="ts" setup>
import { exactType } from 'tsc/shared'
import Child from './child.vue'

const n = 1 as const
</script>

child.vue

<template></template>

<script lang="ts" setup>
defineSlots<{
  action1: (props: { a: string }) => void
  action2: (props: { a: string }) => void
}>()
</script>

@KermanX
Copy link
Collaborator

KermanX commented Aug 8, 2024

Opened #4669 for the type problem.

About the syntax highlighting problem, I think the current behavior is expected:

  1. IMO, syntax highlighting should be as error-tolerant as possible
  2. complex expression is actually supported in SFC: example

@dmichaelnm
Copy link

That worked for me.

function getSlotName(name: string): `body-cell-${string}` {
  return `body-cell-${name}` as unknown as `body-cell-${string}`;
}

@KermanX
Copy link
Collaborator

KermanX commented Aug 21, 2024

That worked for me.

function getSlotName(name: string): `body-cell-${string}` {
  return `body-cell-${name}` as unknown as `body-cell-${string}`;
}

This can be simplified to:

function getSlotName(name: string) {
  return `body-cell-${name}` as const;
}

@tomvdk
Copy link
Author

tomvdk commented Aug 23, 2024

That worked for me.

function getSlotName(name: string): `body-cell-${string}` {
  return `body-cell-${name}` as unknown as `body-cell-${string}`;
}

This can be simplified to:

function getSlotName(name: string) {
  return `body-cell-${name}` as const;
}

This works fine! Thanks!

@tomvdk
Copy link
Author

tomvdk commented Sep 2, 2024

After 2.1.0 release this is now fixed. No need for the workaround above anymore.

<template #[body-cell-${actionsKey}]="data"> works fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 🔨 p3-minor-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants