Skip to content

createProcessFactoryWith doesn't allow for inferring state and payload types #80

@agubler

Description

@agubler

Bug

createProcessFactoryWith is used to create a factory that has pre-applied middleware, but the result process creator doesn't correctly infer types from the commands it's passed.

Package Version: latest

Code

import {
	createCallbackDecorator,
	createCommandFactory,
	createProcessFactoryWith
} from "@dojo/framework/stores/process";

interface State {
	foo: string;
	bar: number;
}

const createCommand = createCommandFactory<State>();

const middleware = (): void => {
    console.log("test");
};

interface Payload {
	qux: string;
}

const command = createCommand<Payload>(() => {
    return [];
});

const middlewareProcess = createProcessFactoryWith([createCallbackDecorator(middleware)]);

const myProcess = middlewareProcess('process', [command]);

Expected behavior:

No errors!

Actual behavior:

Typing error using command with middlewareProcess

Argument of type 'Command<State, Payload>[]' is not assignable to parameter of type '(Command<any, DefaultPayload> | Command<any, DefaultPayload>[])[]'.
  Type 'Command<State, Payload>' is not assignable to type 'Command<any, DefaultPayload> | Command<any, DefaultPayload>[]'.
    Type 'Command<State, Payload>' is not assignable to type 'Command<any, DefaultPayload>'.
      Type 'DefaultPayload' is not assignable to type 'Payload'.
        Property 'qux' is missing in type 'DefaultPayload'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnextIssue/Pull Request for the next major version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions