Hi, Pact Matcher api has a type based matcher 'lik...
# pact-js
h
Hi, Pact Matcher api has a type based matcher 'like', For example, if there are types and a matcher is generated from this type. Will Pact (contract) be created based on typescript type 'TestType'? or Pact will guess the type based on the example value? (In this case, field1, field2 are string). So, essentially, the question is whether 'like' matcher is based on typescript type definition or type inferred from example value.
Copy code
type TestType = {
  field1: string | number;
  field2: TestType2
}

type TestType2 = "option1" | 'option2'

const testData:TestType = {
  field1: 'stringValue',
  field2 'option1'
}

const matcher = MatcherV3.like(testData)
y
Hey, Type is inferred from the value provided, with the
like
matcher
1
so in your case it would be a string
1
h
Thanks for the quick answer! Do you know if there is a plan to support matcher based on typescript type instead of inferred type from provided value? I know that Pact doesn't have a vision to be a schema checker but just to know:)
y
I’m not sure, I probably wouldn’t implement it. You could raise a feature request and ascertain interest? I have seen this project https://github.com/HLTech/pact-gen-ts I haven’t used it however
👍 1
looks like it could be cool though, similar to how annotations are used to generate openapi docs with certain tools
I have a love / hate relationship with type checkers in general
b
Yeah, since Pact is concerned with what is actually sent, not what is "promised" to be sent, I would be surprised if it happens. But I don't think there's anything technically preventing it.