Paul Hill
01/24/2023, 4:05 PMTimothy Jones
01/24/2023, 11:18 PMPaul Hill
01/26/2023, 8:53 AMTimothy Jones
01/27/2023, 6:09 AMTimothy Jones
01/27/2023, 6:09 AMTimothy Jones
01/27/2023, 6:10 AMexport type StateFuncWithSetup = {
setup?: StateFunc;
teardown?: StateFunc;
};Timothy Jones
01/27/2023, 6:14 AM'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
},
},Matt (pactflow.io / pact-js / pact-go)
Paul Hill
02/02/2023, 12:08 PMPaul Hill
02/02/2023, 12:17 PM(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)
Could I have the wrong type defs? (using "@pact-foundation/pact": "^10.4.1" which seems to be latest).Paul Hill
02/02/2023, 12:20 PMPaul Hill
02/02/2023, 12:43 PMtype ShimmedVerifierOptions = Omit<VerifierOptions, 'stateHandlers'> & {
stateHandlers: StateHandlers;
};
const opts: ShimmedVerifierOptions = {
...
stateHandlers: {
'my state': {
setup: async () => {
console.log('setup');
teardown: async () => {
console.log('teardown');
},
},
},
};
...
async () => await new Verifier(opts as VerifierOptions).verifyProvider(),Timothy Jones
02/04/2023, 2:49 AMTimothy Jones
02/04/2023, 2:51 AMinterfaces called StateHandler. To work around it, you can:
1) Downgrade to before the interfaces were merged (I’m not sure when this was)
2) Define your state handlers explicitly as one of the types it accepts (so typescript doesn’t try to figure it out)
3) Use a type assertion as you’re doing (I personally don’t like this way, as it might hide other problems).Timothy Jones
02/04/2023, 2:52 AMTimothy Jones
02/04/2023, 2:54 AMas VerifierOptions by not importing StateHandlers and instead defining it yourself to match exactly one of the state handler definitions.Timothy Jones
02/04/2023, 2:54 AMPaul Hill
02/06/2023, 9:34 AMPaul Hill
02/07/2023, 5:32 PMTimothy Jones
02/07/2023, 10:19 PMPaul Hill
04/14/2023, 11:06 AMStateHandlers and MessageStateHandlers their union via VerifierOptions means a StateFuncWithSetup can't satisfy the MessageStateHandler type.
So while simple StateFunc handlers are typing correctly, the StateFuncWithSetup are not.
Here's an example:
import { MessageStateHandlers, Verifier, VerifierOptions } from '@pact-foundation/pact';
// This is fine.
const stateHandlers: StateHandlers = {
key: {
setup: async () => {
// setup
},
},
};
// This is not
const unionStateHandlers: StateHandlers & MessageStateHandlers = {
key: {
setup: async () => {
// setup
},
},
};
/* VerifierOptions results in:
* stateHandlers expecting `(property) ProxyOptions.stateHandlers?: (StateHandlers & MessageStateHandlers) | undefined`
*/
I don't think I'm doing anything incorrect here, but if I am just being a dummy please do point it out 🙂 Happy to raise a new issue if you'd like?Timothy Jones
04/14/2023, 11:14 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Paul Hill
04/27/2023, 8:13 AMTimothy Jones
04/27/2023, 8:35 AMTimothy Jones
04/27/2023, 8:37 AMStateHandlersTimothy Jones
04/27/2023, 8:38 AMStateHandlers, then I don’t know why you’d expect StateHandlers & MessageStateHandlers to compile. What are you trying to achieve?Timothy Jones
04/27/2023, 8:40 AMStateHandlers and MessageStateHandlers are not compatibleTimothy Jones
04/27/2023, 8:42 AMStateHandlers and MessageStateHandlers their union via VerifierOptions means a StateFuncWithSetup can’t satisfy the MessageStateHandler type.Yes, that’s right. This is the problem that separating the types corrected. In your example, you’re putting them back together?
Timothy Jones
04/27/2023, 8:42 AM