-
Notifications
You must be signed in to change notification settings - Fork 16
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
This expression is not callable.
using with TypeScript
#104
Comments
Not sure if this relates, but I had the same error message and it was caused by how I was importing.
|
I mean yes, this is an aspect of ESM imports. By nature, a wildcard import is an object namespace of all exports from that location. A plain object is never callable, so naturally that would be the case. Nothing specific to this package; this is just how JS works. If you wanted to use the namespace import, then you would have to refer to the default export (what the second line refers to) explicitly: import * as memoize from 'micro-memoize';
const foo = memoize.default((bar: string => bar); There really isn't much benefit to using the namespace, though, as there are no other exports than the default. |
I believe it related to types, which is how I personally ended up down that road. I had a map the default import to a singleton variable to get around the require purge in Remix's hot reloads. However the variable would throw a type any warning, and importing the namespace resolved that initial typing issue, but then I came across the issue that the namespace was not callable. To resolve the typing issue, I ended up adding this line.
|
I'm actually even more confused now, and am curious what you would need to type in this way. Can you provide a more complete repro? A TS playground, tiny repo with code I can pull in, something that shows what the actual issue is. |
Example showing typing scenario that was described by me above The routes aren't working properly, I assume it's some stackblitz thing but I don't have time to debug. The Remix Run dev server, purges the require cash on hot reload, which means Within the
There is probably some fancy way of fixing this, but this worked so I moved on. When I checked the issues of this project, I noticed that I had not callable issue when debugging my issue and thought I would reply as importing the namespace is sometimes promoted as a fix for typing issues (I don't know why). While redundant, if you wanted to see the actual pages. You may need to run |
This again looks like a gap in understanding, in this case how TS works with requires. By default, TS will widen anything returned from A common hack to work around this is to do a typing like this: require('micro-memoize') as typeof import('micro-memoize') Casting as the type of the import itself causes automatic inheritance of the package types without the dance you're doing locally. That said, I'm going to close this issue because I'm not seeing any issues specific to the package. If you can provide a simple repro to showcase an issue with the package types, feel free to open another issue. |
Refer: davidjerleke/embla-carousel#481
The text was updated successfully, but these errors were encountered: