deepmerge: typescript type definition is wrong

this code:

import * as deepmerge from 'deepmerge';

const obj1 = {a:'a'};
const obj2 = {b:'b'};
const merge = deepmerge(obj1, obj2);

causes this error: Cannot invoke an expression whose type lacks a call signature. Type 'typeof import("/.../node_modules/deepmerge/index")' has no compatible call signatures.

the type definition in DefinitelyTyped seems to be correct. the difference is that index.d.ts has a default export, but the code doesn’t really have one

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 22 (15 by maintainers)

Commits related to this issue

Most upvoted comments

As of 3.0.0, there is no ES Module export any more. This should prevent any of this confusion. All hail Webpack, the broken bundler that everyone uses!

There were no other changes between 2.2.1 and 3.0.0, so everyone should be able to immediately upgrade to deepmerge@3 and not have import/require issues any more. The TypeScript definition is correct with 3.0.0, no matter what bundler you’re using.

Either of these should work, even with Webpack, even as a transitive dependency:

import * as deepmerge from 'deepmerge'
const deepmerge = require('deepmerge')

For version 4 I had to use const deepmerge = require('deepmerge') for it to work with jest tests. The import * as deepmerge from 'deepmerge' style gave me the lack call signature error. I don’t know why, wish I did.

It’s not a great experience to require devs manually setting a TS config flag for this package to work, but either way - thanks for the fast reply.

No worries, I’m writing a quick and dirty one in another branch.