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
This can cause errors with TypeScript, depending on tsconfig.json settings. For example:
If using CommonJS (e.g., package.json "type": "commonjs") and tsconfig.json "module": "node16", "moduleResolution": "node16", then everything works.
If using ESM (e.g., package.json "type": "module") and tsconfig.json "module": "node16", "moduleResolution": "node16", problems arise:
If you try to import and use memoizeOne directly, the TypeScript compiler throws an error at compile time:
importmemoizeOnefrom'memoize-one';// This expression is not callable.// Type 'typeof import("node_modules/memoize-one/dist/memoize-one")' has no call signatures.ts(2349)constmemoized=memoizeOne((a: number,b: number)=>a+b);
However, if you work around that by adding .default, you get an error at runtime:
importmemoizeOnefrom'memoize-one';// TypeError: memoizeOne.default is not a functionconstmemoized=memoizeOne.default((a: number,b: number)=>a+b);
As I understand it, there are two possible solutions:
Hand-write a .d.ts file that reflects the CommonJS export assignment approach used by the Rollup-generated memoize-one build. (There may be a way to get tsc to do this for you, but I haven't been able to figure it out.) I believe that this could be done in a semver-patch release.
Add full-fledged module support: update memoize-one's package.json to export its ESM build via exports (so Node.js, and TypeScript when using node16 module resolution, can see it), with ESM-specific types. This may be a semver-major change.
If you're interested in one of these approaches, I can try and open a PR.
The text was updated successfully, but these errors were encountered:
According to Are the Types Wrong, memoize-one has an incorrect default export.
This can cause errors with TypeScript, depending on tsconfig.json settings. For example:
"type": "commonjs"
) and tsconfig.json"module": "node16", "moduleResolution": "node16"
, then everything works."type": "module"
) and tsconfig.json"module": "node16", "moduleResolution": "node16"
, problems arise:memoizeOne
directly, the TypeScript compiler throws an error at compile time:.default
, you get an error at runtime:As I understand it, there are two possible solutions:
.d.ts
file that reflects the CommonJS export assignment approach used by the Rollup-generated memoize-one build. (There may be a way to get tsc to do this for you, but I haven't been able to figure it out.) I believe that this could be done in a semver-patch release.exports
(so Node.js, and TypeScript when usingnode16
module resolution, can see it), with ESM-specific types. This may be a semver-major change.If you're interested in one of these approaches, I can try and open a PR.
The text was updated successfully, but these errors were encountered: