<#1057 Two StateHandler types defined> Issue creat...
# pact-js-development
g
#1057 Two StateHandler types defined Issue created by paul-kuihi Software versionsOS: Mac OSX 13.1 • Consumer Pact library: Pact JS v10.4.1 • Provider Pact library: Pact JS v10.4.1 • Node Version: 18.12.1 Issue Checklist Please confirm the following: ☑︎ I have upgraded to the latest ☐ I have the read the FAQs in the Readme ☑︎ I have triple checked, that there are no unhandled promises in my code and have read the section on intermittent test failures ☐ I have set my log level to debug and attached a log file showing the complete request/response cycle ☐ For bonus points and virtual high fives, I have created a reproduceable git repository (see below) to illustrate the problem I raised this in the pact-js slack channel and was asked to raise this issue. Expected behaviour Creating StateHandlers as per the documentation results in no Typing errors from TS. Actual behaviour When attempting to use the setup/teardown properties on the provider state handlers Typescript complains that it doesn't match the type it's expecting. TS is finding two types with the same name and merging them (StateHandlers I believe). It gives the error:
Copy code
(property) 'my state': {
    setup: () => Promise<void>;
    teardown: () => Promise<void>;
}
Type '{ setup: () => Promise<void>; teardown: () => Promise<void>; }' is not assignable to type 'StateHandler & ((state: string, params?: { [name: string]: string; } | undefined) => Promise<unknown>)'.
  Type '{ setup: () => Promise<void>; teardown: () => Promise<void>; }' is not assignable to type 'StateFuncWithSetup & ((state: string, params?: { [name: string]: string; } | undefined) => Promise<unknown>)'.
    Type '{ setup: () => Promise<void>; teardown: () => Promise<void>; }' is not assignable to type '(state: string, params?: { [name: string]: string; } | undefined) => Promise<unknown>'.
      Type '{ setup: () => Promise<void>; teardown: () => Promise<void>; }' provides no match for the signature '(state: string, params?: { [name: string]: string; } | undefined): Promise<unknown>'.ts(2322)
Steps to reproduce Create a state handler definition such as:
Copy code
'Whatever your state name is': {
    setup: (parameters) => {
      // do your setup here
      // return a promise if you need to
    },
    teardown: (parameters) => {
      // do your teardown here
      // return a promise if you need to
    },
  },
TS will complain as above. As a workaround, we've created a shim type. An alternative as mentioned by @Timothy Jones in the slack thread is to define your own StateHandler type until this is fixed up. Relevant log files N/A pact-foundation/pact-js