GitHub
02/02/2023, 11:40 PMwillRespondWith/body you need to wrap them in InterfaceToTemplate or use type instead of interface.
I've tried both but the results where not quite satisfactory.
As far as I understand it would be beneficial to use existing `type`s and `interface`s to prevent typos and to define the correct expected value types for the mock server.
On the other hand, Matcher.<something> seems incompatible with the types expected by interface members. The example from the docs only uses the like matcher around the interface, but not for its members.
My question is how I would be able to achieve something like this with Pact:
interface Foo {
a: string;
}
const f: InterfaceToTemplate<Foo> = { a: like("working example") };
// The above causes:
// Type 'Matcher<"working example">' is not assignable to type 'AnyTemplate'.
// Type 'Matcher<"working example">' is not assignable to type 'TemplateMap'.
// Index signature for type 'string' is missing in type 'Matcher<"working example">'.
provider.addInteraction({
uponReceiving: "a post with foo",
withRequest: {
method: "POST",
path: "/",
body: like(f)
},
...
})
The only thing that comes to mind is to slap as unknown as string after the matcher.
Software versions
• OS: macOS Ventura
• Consumer Pact library: Pact JS 10.4.1
• Node Version: v16.19.0
pact-foundation/pact-jsGitHub
02/16/2023, 11:54 AM