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

TypeScript: Vue types $attrs should be type Record<string, any> #9772

Open
baseprime opened this issue Mar 25, 2019 · 1 comment · May be fixed by #9773
Open

TypeScript: Vue types $attrs should be type Record<string, any> #9772

baseprime opened this issue Mar 25, 2019 · 1 comment · May be fixed by #9773

Comments

@baseprime
Copy link

baseprime commented Mar 25, 2019

Version

2.6.10

What is expected?

Vue.prototype.$attrs should be type Record<string, any> and not Record<string, string>.

Since 2.4.0, vm.$attrs has contained extracted bindings not recognized as props. The type of these values is unknown.

Steps to reproduce

Take the following component:

new Vue({
  data: function () {
    return {
      count: 0
    }
  },
  mounted() {
    let someFunc = this.$attrs.someBoundAttr as Function
    // Type 'string' cannot be converted to type 'Function'
  },
  template: `
    <button v-on:click="count++" :someBoundAttr="() => count">
      You clicked me {{ count }} times.
    </button>`
})

Notice the error in TypeScript checking:

Type 'string' cannot be converted to type 'Function'

What is actually happening?

...

Reproduction link

http://www.typescriptlang.org/play/

@posva
Copy link
Member

posva commented Mar 26, 2019

It's true that $attrs can be more than strings, but they come from the parent not the component itself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants