-
-
Notifications
You must be signed in to change notification settings - Fork 935
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
The types aren't compatible with CommonJS #1137
Comments
You forgot that it also extends |
What TypeScript version are you using? |
Oops, right you are! I did miss that.
I am using the latest version of both Got (10.7.0) and TypeScript (3.8.3). Outside the default configuration, I've tried a few additional options to see if anything helps, to no avail unfortunately ( Based on the error message and what else I've been able to find of it, not sure if it might have something to do with it being unable to match any of the signatures of
To be clear, I'm just throwing ideas out there based on my attempts to resolve this. Not sure if any of it is applicable. To me, it seems like the minimal code example in the original comment should be sufficient to work without errors. |
Please set up an example repository. |
Running into this issue as well |
I cannot reproduce this. |
@szmarczak Would a CodeSandbox demo work? https://codesandbox.io/s/js-typescript-got-demo-qirz5 Ignoring the preview, and waiting a moment for the dependencies to load, you should see the inline error when |
Also not sure if this is related, but I was encountering a very similar error when using an older version of the |
@aduth Why are you trying to run Got in a browser sandbox? Got doesn't support browsers. |
Please set up a GitHub respository so I can just clone and look what's wrong. |
Please try replacing export default got;
// For CommonJS default export support
module.exports = got;
module.exports.default = got;
export * from './create';
export * from './as-promise'; with export = got; then recompile Got and try again. |
Also why are you running |
This is useful when migrating a large javascript codebase to typescript bit-by-bit with the |
I've pushed a repository including a minimal reproducible case here: https://github.com/aduth/tmp-got-types-demo Reproduce by:
CodeSandbox can interpret the TypeScript configuration, which is what I'd intended to demonstrate with the inline error reporting. The runtime of the code itself isn't particularly relevant for the problem.
As @Caerbannog mentioned, it's a supported feature of TypeScript: https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html
I can check this later and report back with the results. |
As a workaround I migrated to typescript the few |
That'd be awesome. |
I had some success with this, though the changes as proposed weren't quite as easy to implement. I'm not sure if code you referenced is from a version older than that of the current Lines 117 to 161 in 74d66b2
Ultimately, it did seem to be resolved by using import got from './index-original';
export = got; This built fine, fixed the error in my JavaScript project, and provided the type hints I'd hope for. I can open a pull request if you'd like, or leave it to you or another maintainer, as I expect it might need some further thought on how these files are structured if there needs to be the one entrypoint with one |
Aside: I use the TypeScript tooling in quite a few of my JavaScript projects, with no plans to adopt TypeScript the language. I'd consider it a perfectly valid use-case, in addition to the scenario you describe. |
Having the same issue but when trying to call |
By the way, I managed to get around this by doing: const { default: got } = require('got');
got.extend({ … }); |
Fixed in #1667 |
Describe the bug
Standard usage of the default export
got
as a callable expression yields a type error in TypeScript "This expression is not callable".Possible factors include:
I observe in the generated types...
import("./create").Got
Got
isinterface extends Record
, not a function (source)Possibly the types generated are not able to correctly detect type from the creation of the default export here:
got/source/index.ts
Line 115 in 5c74084
Actual behavior
Expected behavior
(No type errors)
Code to reproduce
package.json
index.js
(Code based on the Runkit example. Note: The current example appears to be broken, based on
json: true
needing to beresponseType: 'json'
)Checklist
The text was updated successfully, but these errors were encountered: