Repository navigation
eslint complains about no-unnecessary-type-assertion when typing a dictionary-type state variable
#3133
|
Hi! I am using a pinia store with a state variable that is supposed to store a dictionary, initially empty. The definition is like this: Since upgrading my but I need the assertion because otherwise, pinia will not know and forward the correct type. Am I missing the proper way to handle this? |
Replies: 2 comments
|
The rule is only checking assignability there, not inference. Cleanest fix that keeps both eslint and the type happy is to type the whole interface State {
contourContainers: Record<string, ContourContainer>
}
state: (): State => ({ contourContainers: {} }),No assertion, so |
|
You can disable the rule, it doesn’t seem to fit your usage. It might be worth considering doing |
You can disable the rule, it doesn’t seem to fit your usage. It might be worth considering doing