In my Vuex component using Typescript, I want to add types to the mapping functions in mapState
. Previously, I had it set up like this:
@Component({
computed: {
...mapState( MY_NAMESPACE, {
fooIndex: ( state: MyModel ) => state.values.indexOf('foo')
})
// more computed props here
}
})
export default class MyComponent extends Vue {}
This used to work fine, but after updating my dependencies, I'm now encountering an error saying
No overload matches this call.
Overload 1 of 6, '(namespace: string, map: string[]): { [x: string]: Computed; }', gave the following error.
To address this issue, I can remove the type from the function parameter and cast it like so:
@Component({
computed: {
...mapState( MY_NAMESPACE, {
fooIndex: state => (state as MyModel).values.indexOf('foo')
}),
}
})
export default class MyComponent extends Vue {}
Is there a more optimal way to define the types in this scenario?