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
- fix type definition fixes issue #120 remove default export — committed to nataly87s/deepmerge by nataly87s 6 years ago
- Updating deepmerge version - https://github.com/TehShrike/deepmerge/issues/120#issuecomment-450384977 — committed to fernandoruaro/excel4node by fernandoruaro 5 years ago
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:
For version 4 I had to use
const deepmerge = require('deepmerge')for it to work with jest tests. Theimport * as deepmerge from 'deepmerge'style gave me the lack call signature error. I don’t know why, wish I did.@luiscla27 it’s used here https://github.com/Soluto/shisell-js/blob/master/src/internal/AnalyticsContext.ts
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.