-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed as not planned
Closed as not planned
Copy link
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
π Search Terms
Function generic unmatched
π Version & Regression Information
- This is marybe bug?
- The versions is 5.4.5
β― Playground Link
π» Code
export type StateFunction<State> = (
s: State,
...args: any[]
) => any;
export type VuexStoreOptions<
State,
Modules,
> = {
state?: State | (() => State) | { (): State };
mutations?: Record<string, StateFunction<State>>;
modules?: {
[k in keyof Modules]: VuexStoreOptions<Modules[k], never>
};
}
export function createStore<
State extends Record<string, unknown>,
Modules extends Record<string, Record<string, unknown>>,
>(options: VuexStoreOptions<State, Modules>) {
}
const store = createStore({
state() { return { bar2: 1 } },
mutations: { inc: (state123) => state123.bar2++ },
modules: {
foo: {
// state: () => ({ bar2: 1 }), // This match the state;
// state: function () {
// return { bar2: 1 };
// }, // But this can't
state() {
return { bar2: 1 };
}, // and This can't
// state: { bar2: 1 },
mutations: { inc: (state) => state.bar2++ },
},
},
});
π Actual behavior
If use arrow function or obj method function to declare the state in modules.foo
Got error:
'state.bar2' is of type 'unknown'.
But arrow function won't.
π Expected behavior
No matter which one i use to declare the fucntion ( arrow function, method function or just function),
the state can be known in mutations param
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created