benjamine / jsondiffpatch

Diff & patch JavaScript objects
MIT License
4.86k stars 473 forks source link

Add undefined to 'patch()' typing #264

Closed ulrichb closed 4 years ago

ulrichb commented 5 years ago

This is necessary for TypeScript's --strictNullChecks mode, otherwise the result of diff() (which correctly is Delta | undefined) cannot be provided as input for patch() because before this PR it only accepts the Delta type (without undefined).

The corresponding JS: https://github.com/benjamine/jsondiffpatch/blob/0c4323e9bff23ae231f4bff231ceed4df2b48be5/src/filters/trivial.js#L64-L66


An alternative would be to include undefined to the Delta type itself, iff all operations with a Delta input can cope with an undefined input (which I didn't check).

benjamine commented 4 years ago

@ulrichb sorry for the delays, but yes, deltas should always contemplate the undefined value (meaning no diff between left and right). do you think we can add that to the definition of Delta?

ulrichb commented 4 years ago

@benjamine Sry, don't use jsondiffpatch anymore.