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

Incorrect ts(2783) error when class attribute appear in template syntax more than once after update vue-tsc to latest version #2166

Closed
mmis1000 opened this issue Dec 2, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@mmis1000
Copy link

mmis1000 commented Dec 2, 2022

Versions

"typescript": "^4.9.3",
"vue-tsc": "^1.0.10"

<template>
  <div class="a" v-bind="{ class: {b: true} }" />
</template>

This cause an error that don't actually exist

error TS2783: 'class' is specified more than once, so this usage will be overwritten.

Because vue sfc explicitly allow multi class and style to exist at same time, vue-tsc should not report error on such usage.

The template above outputs as

function render(_ctx, _cache) {
  return (_openBlock(), _createElementBlock("div", _mergeProps({ class: "a" }, { class: {b: true} }), null, 16 /* FULL_PROPS */))
}

Which works totally fine and nothing is overwritten.

@sawmurai
Copy link

sawmurai commented Dec 2, 2022

Getting the same error with this:

<slot name="label" v-bind="{name}">
<!-- ... -->
</slot>

Error:

'name' is specified more than once, so this usage will be overwritten.ts(2783)

@cawa-93
Copy link

cawa-93 commented Dec 13, 2022

From docs:

In addition, the :class directive can also co-exist with the plain class attribute. So given the following state:

Unlike other attributes, class and style are not overwritten, but combined from all attributes. See demo: https://stackblitz.com/edit/vitejs-vite-vvfozp?file=src/App.vue

@johnsoncodehk johnsoncodehk added the bug Something isn't working label Dec 25, 2022
@sawmurai
Copy link

Hello! I'm afraid the error case with a duplicate name still exists:

<slot name="label" v-bind="{name}">
<!-- ... -->
</slot>

@cawa-93
Copy link

cawa-93 commented Dec 28, 2022

@sawmurai I think for name is correct error sinse vue will owerride it. Only class, style and onXX props may be merged.
See https://github.com/vuejs/core/blob/c6e5bda27d13554675d68dbe33b07f3474467aa6/packages/runtime-core/src/vnode.ts#L816-L845

@sawmurai
Copy link

Thinking about it, maybe the special case here is v-bind or slot-bindings in general :)

@sawmurai
Copy link

sawmurai commented Jan 3, 2023

@johnsoncodehk Do you want me to open a new issue maybe?

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

Successfully merging a pull request may close this issue.

4 participants