Currently InvalidPatch and PatchApplyError are being exported as interfaces, i.e. static only.
Classes are useful at runtime for distinguishing between errors.
Workaround:
import { apply_patch, InvalidPatch, PatchApplyError } from 'jsonpatch';
declare module 'jsonpatch' {
export class InvalidPatch extends Error {}
export class PatchApplyError extends Error {}
}
try {
apply_patch(document, patch);
}
catch (e: unknown) {
if (e instanceof InvalidPatch) {
console.error('Invalid patch format');
}
}