setDefaultMutation returns the right type

This commit is contained in:
Yanick Champoux 2024-08-09 11:50:55 -04:00
parent 90e90779e1
commit 2f687cfda3
2 changed files with 13 additions and 1 deletions

View File

@ -210,7 +210,7 @@ export default class Updux<D extends DuxConfig> {
setDefaultMutation(
mutation: Mutation<any, DuxState<D>>,
terminal?: boolean,
);
): Updux<D>;
setDefaultMutation(mutation, terminal = false) {
this.#defaultMutation = { terminal, mutation };
return this;

View File

@ -98,3 +98,15 @@ test('actionType as string', () => {
dux.addMutation('unknown', () => (x) => x);
}).toThrow();
});
test('setDefaultMutation return value', () => {
const dux = new Updux({
initialState: 13,
});
let withDM = dux.setDefaultMutation(() => (state) => state);
expect(withDM).toEqual(dux);
expectTypeOf(withDM.initialState).toBeNumber();
});