Closed ishpagin closed 4 years ago
I believe this is to be expected. Unlike ky
, which is a pure ES module, ky-universal
is a CommonJS module. I think Sindre did it this way because CommonJS is still a little easier to consume in the Node.js ecosystem.
By the way, it is probably better to write:
import ky = require('ky-universal');
My understanding is that const ... require()
returns the module with type any
, whereas import ... require()
returns the correct type.
Hi @sholladay,
Thank you for quick response.
import ky = require('ky-universal')
This way shows me only "ky.default.post" path in hints in vscode and works incorrectly because ky-universal exported object that doesn't have the "default" field and app crashed in runtime. If I don't use the "default" field it shows error with compiling and linting in TS.
My solution is add the definition of "ky-universal" module
// ky.d.ts
declare module 'ky-universal' {
import ky from 'ky';
export = ky
}
Can we add this definition to fix IDE hits and typescript compiler errors?
I think this is a problem with our type definition. I think it should be changed to:
import ky from 'ky';
export = ky;
which is the correct CommonJS syntax.
@sindresorhus
Yes, it can be the solution.
Should I create PR or would you be able to delegate this change to someone?
I have submitted PR #17 to fix that issue @ishpartko. After it is merged and released, your workaround should no longer be necessary.
Hi all,
Don't working default import in ts, like
import ky from 'ky-universal'
is undefiend but:is working