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

Fallthrough attributes not recognized since 1.0.3 #1986

Closed
abompard opened this issue Oct 11, 2022 · 7 comments
Closed

Fallthrough attributes not recognized since 1.0.3 #1986

abompard opened this issue Oct 11, 2022 · 7 comments
Labels
question Further information is requested

Comments

@abompard
Copy link

Hey! I have this wrapper component:

<template>
  <li class="nav-item">
    <router-link v-bind="$attrs" class="nav-link"><slot /></router-link>
  </li>
</template>

<script lang="ts">
export default {
  inheritAttrs: false,
};
</script>

(very standard way of doing a wrapper attribute as described in vue's docs). I'm calling it like this:

<MainNavLink to="/rules">Rules</MainNavLink>

So I am passing the to property. And vue-tsc gives me this error since upgrading to 1.0.3:

> vue-tsc --noEmit -p tsconfig.vitest.json --composite false

src/components/MainNavLink.vue:3:6 - error TS2322: Type '{ class: string; }' is not assignable to type 'ComponentProps<_RouterLinkI>'.
  Property 'to' is missing in type '{ class: string; }' but required in type 'RouterLinkProps'.

3     <router-link v-bind="$attrs" class="nav-link"><slot /></router-link>
       ~~~~~~~

  node_modules/vue-router/dist/vue-router.d.ts:1153:5
    1153     to: RouteLocationRaw;
             ~~
    'to' is declared here.

It did not give me this error on 0.40.0. I did look at #1384 but I don't think it's the same issue, since it worked fine in 0.40.0.

Is there something else I should do after upgrading to 1.0.x to enable support for fallthrough attributes?

@johnsoncodehk
Copy link
Member

Just one of the ways, but you can try:

<template>
  <li class="nav-item">
    <router-link v-bind="$attrs" class="nav-link">
      <slot />
    </router-link>
  </li>
</template>

<script lang="ts">
import { RouterLink } from 'vue-router';

export default {
  inheritAttrs: false,
} as unknown as new () => {
  $props: InstanceType<typeof RouterLink>['$props'],
  $attrs: any,
};
</script>

@abompard
Copy link
Author

Okay, it does work but it feels a bit complex. Is this the recommended way to do fallthrough attributes?

@johnsoncodehk
Copy link
Member

It can be simplify.

<script lang="ts">
import { DefineComponent } from 'vue';
import { RouterLink } from 'vue-router';

export default {
  inheritAttrs: false,
} as typeof RouterLink & DefineComponent;
</script>

Is this the recommended way to do fallthrough attributes?

It just a workaround from me. I don't know what is the community consensus. You can try ask in TypeScript channel of Vue discord server.

@johnsoncodehk johnsoncodehk added the question Further information is requested label Oct 18, 2022
@coader
Copy link

coader commented Apr 22, 2023

any better solution?

@voidus
Copy link

voidus commented Jan 17, 2024

This seems like a serious impediment to quality

@so1ve
Copy link
Member

so1ve commented Jan 17, 2024

@voidus A lot of work is required to perform static analysis. I will look into this.

@so1ve so1ve added enhancement New feature or request and removed enhancement New feature or request labels Jan 17, 2024
@so1ve
Copy link
Member

so1ve commented Jan 17, 2024

Oh I just see you can use defineProps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants