diff: import of deep-diff to Typescript broken with 0.3.5 and 0.3.6

When the releases of the past 2 days, my current code is now broken. I believe this has to do with the imports of the package. This would be fine, except for two things:

  1. The version number updates should be compliant with SEMVER standards and issue a breaking change (IE. 0.4.0, not 0.3.x).
  2. The documentation (README etc) has no explanation of the import requirements of the package that are not ancient es versions.

On previous versions of deep-diff up until 0.3.4, my working code imported this package as:

import { diff } from 'deep-diff';
.. .. ..
.. .. ..
let isDifferent = diff(lh, rh);

This worked excellently. With the release of 0.3.5 and 0.3.6, the compiler now chokes on this import by stating flatly: TypeError: deep_diff_1.diff is not a function

Punting to a catch-all import like this:

import * as dDiff from 'deep-diff';

also does no good.

I’m losing my mind trying to understand the change and how it can be accommodated and used in Typescript. I tried reviewing the ‘@types/deep-diff’ was no more helpful as it seems not to be current.

What export changes were made to deep-diff, and how should Typescript users now adjust to import this package? (again, all of this could be resolved instantly if there was a useful README.)…

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Kinda hackish, isn’t it? 😃

I hoped for true es6 import like import { deepDiff} from 'deep-diff' or import deepDiff from 'deep-diff'

I am trying to solve this issue by translating the methods definition for named exports. With that I was able to solve all cases pointed here, but when you you this module in a CommonJS environment, the following code will throw an error.

var dd = require('deep-diff')
// ...
dd(lhs, rhs)

Will be needed to specify the method.

var dd = require('deep-diff')
// ...
dd.dif(lhs, rhs)
// or
dd.default(lhs, rhs)

But it will work like a charm in ES2015/Typescript code.

import {default as diff} from 'deep-diff'; // explicit 'default'
// is equal to:
import diff from 'deep-diff'; // implicit 'default'
// is equal to:
var a = require('deep-diff').default;

While there is still no definitive solution, you could do:

import {default as dDiff} from 'deep-diff'

let isDifferent = dDiff.diff(lh, rh);

Any solution here?

import { diff } from 'deep-diff' is broken, no diff found

Please reconfirm with v1.0.0-pre.x

Install with npm:

npm install deep-diff@next

Many styled imports, diff, DeepDiff, are interchangeable and refer to the same function, the API functions are properties of the default export:

Plain

const diff = require('deep-diff');
// const DeepDiff = require('deep-diff');
import diff from 'deep-diff';
// import DeepDiff from 'deep-diff';

Destructure(ish)

const { diff } = require('deep-diff');
// const DeepDiff = require('deep-diff');
import { diff } from 'deep-diff';
// import { DeepDiff } from 'deep-diff';