hi! pact-js v 10.4 ``` includeWipPactsSince...
# pact-js
d
hi! pact-js v 10.4
Copy code
includeWipPactsSince: isCI ? new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString().split("T")[0] : undefined,
throws
TypeError: includeWipPactsSince
doesnt work properly in non-CI env, with any of undefined/null/“” any ideas ?
Copy code
includeWipPactsSince?: string;
which [empty] string will make it happy ? 🙂
t
Yes?
What is your question?
Copy code
includeWipPactsSince?: string;
^ This says the property
includeWipPactsSince
is optional. And it must be a string
So, it’s not valid to set it to
undefined
or
null
, because they are not strings
The proper way to write what you are asking about is:
Copy code
...(isCI
    ? {
        includeWipPactsSince: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000)
          .toISOString()
          .split('T')[0],
      }
    : {}),
d
awesome, will try, thank you :)
t
Welcome. This is one place where typescript differs from how you’d write it in plain JS
I personally prefer the typescript way, because it’s more explicit. But, I can see why there might be preferences for the other way, as the optional spread idiom isn’t always clear
Also I’m pretty sure you can’t tell the difference between
{ someProp: undefined }
and
{}
, even if typescript thinks you can
😄 1
🤷‍♂️
Update: you can: