jsondiffpatch icon indicating copy to clipboard operation
jsondiffpatch copied to clipboard

Typescript: how to get an hold on BaseFormatter

Open FritzHerbers opened this issue 5 years ago • 1 comments

I am trying to get an hold on BaseFormatter, but only something like base is exported (jsondiffpatch.esm.js).

https://stackblitz.com/edit/typescript-sgf4s2

How do I get BaseFormatter imported and get rid of any Typescript errors? Thanks for your help.

Also noticed: In d.ts the provided jsonpatch formatter is missing.

FritzHerbers avatar Oct 24 '18 15:10 FritzHerbers

I just figured it out:

import { formatters } from 'jsondiffpatch';

export class CeosPropertyDiffFormatter extends (formatters as any).base.default {
...
}

kareljuricka avatar Oct 30 '19 20:10 kareljuricka

As of v0.6.0, you should now able to import the base formatter like so:

import BaseFormatter from 'jsondiffpatch/formatters/base';
import type { BaseFormatterContext } from 'jsondiffpatch/formatters/base';

export class CeosPropertyDiffFormatter extends BaseFormatter<BaseFormatterContext> {
  // impl
}

Let us know if you have any further issues.

Methuselah96 avatar Dec 15 '23 15:12 Methuselah96