You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently example usage (written for CommonJS modules) doesn't work for ES modules (aka ESM where application has "type": "module" in package.json), because default exports don't play nice with ESM.
This affects both TypeScript and vanilla JS (with ES, not CommonJS modules), but if you'd use TypeScript, you would get a compile-time error when using like in the example from readme:
src/main.ts:9:27 - error TS2349: This expression is not callable.
Type 'typeof import("/home/ats/proj/easypark/productivity/github-patcher/node_modules/await-to-js/dist/types/await-to-js")' has no call signatures.
9 const [err, data] = await to<ServerResponse>(p)~~
Workaround
To work around it, you would need to replace to( with to.default(, like this:
This is nasty - it requires different usage for ESM and CommonJS (can't use the same approach for both module systems).
ESM compatible nicer solution
Instead of exporting only default export (that would keep backwards compatibility for CommonJS), you could also add named export for the same function, so that applications, that use ES modules could use
Problem
Currently example usage (written for CommonJS modules) doesn't work for ES modules (aka ESM where application has
"type": "module"
inpackage.json
), because default exports don't play nice with ESM.This affects both TypeScript and vanilla JS (with ES, not CommonJS modules), but if you'd use TypeScript, you would get a compile-time error when using like in the example from readme:
Workaround
To work around it, you would need to replace
to(
withto.default(
, like this:This is nasty - it requires different usage for ESM and CommonJS (can't use the same approach for both module systems).
ESM compatible nicer solution
Instead of exporting only default export (that would keep backwards compatibility for CommonJS), you could also add named export for the same function, so that applications, that use ES modules could use
(that also would work for CommonJS modules)
instead of the default import + workaround mentioned above:
The text was updated successfully, but these errors were encountered: