Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript error on update method: TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'typeof "/immutability-helper/index"' has no compatible call signatures. #96

Closed
ajalgaonkar opened this issue Feb 16, 2018 · 11 comments

Comments

@ajalgaonkar
Copy link

I am currently getting the following issue:
TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'typeof "~/node_modules/immutability-helper/index"' has no compatible call signatures.

This issue does not happen on the 2.6.4 version but as soon as the solution pulled in the 2.6.5 version i started getting this issue.
For now I have made the version constant at 2.6.4, but wanted to notify you about this issue.

Thanks.

@andreiglingeanu
Copy link
Collaborator

andreiglingeanu commented Feb 16, 2018

Thanks. Could you please post a code snippet so that we can reproduce the problem?

@chitswe
Copy link

chitswe commented Feb 17, 2018

@ajalgaonkar You need to change import statement. Use import update from "immutability-helper"; instead of import * as update from "immutability-helper". Because typescript type declaration file has been changed in 2.6.5.

@andreiglingeanu
Copy link
Collaborator

I believe yes, we did this change. I think it's better to just have a default export & everyone should be using import update from "immutability-helper";

@DavidHall
Copy link

I have hit the same problem with the typescript definition change in 2.6.5, and although changing my import from import * as update from "immutability-helper" to import update from "immutability-helper" does resolve the compiler error, I now hit run time errors.

The run time error I see is:

TypeError: immutability_helper_1.default is not a function

And that is just from a standard call like:

const newData = update(myData, {
    x: {y: {z: {$set: 7}}},
    a: {b: {$push: [9]}}
});

It could be that the problem is somewhere in my webpack setup, with that not correctly identifying the default export as a function.

One work around that I found is to call the newContext() function to create a new function that does work:

import { newContext } from "immutability-helper";
const update = newContext();

@chitswe
Copy link

chitswe commented Feb 19, 2018

@DavidHall I also have the same problem like you with new version. I thought it could be the problem with webpack configuration. So I didn't report it here.

@andreiglingeanu
Copy link
Collaborator

Oh, this sounds bad, I guess it's because we have declared the update function as a default ES6 export in typings & in the actual source code we have a common JS export module.exports = newContext().

I guess we'll need the typings to fix the library code to get it working, at least because the README says that an ES6 default import is a valid way of consuming the lib: import update from 'immutability-helper';

@vvolodin
Copy link

vvolodin commented Feb 22, 2018

any workaround for this? having runtime errors too. importing {newContext} does not compile for me.

update: my solution to this was using the older * as syntax and casting it to any after importing...

@atfzl
Copy link

atfzl commented Feb 27, 2018

@andreiglingeanu instead of:

module.exports = newContext();
module.exports.newContext = newContext;

we should change it to:

module.exports = newContext();
module.exports.default = newContext();
module.exports.newContext = newContext;

It is working after adding default export here.

@andreiglingeanu
Copy link
Collaborator

andreiglingeanu commented Mar 2, 2018

It seems like that is the way to go, a bit hacky though...

I opened a PR for that, please try it

@ob-ivan
Copy link

ob-ivan commented Mar 5, 2018

For those who are like me:

find src -name '*.tsx' | xargs sed -i 's/import \* as update from "immutability-helper";/import update from "immutability-helper";/'

@bhagyas
Copy link

bhagyas commented May 18, 2018

Issue continues to exist on 2.7.0. Downgrading the dependency version to 2.6.4 seems to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants