Skip to content

Feature request: add InvalidPatch and PatchApplyError classes to TypeScript export #41

@Kinrany

Description

@Kinrany

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');
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions