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
* Fix types for .cjs build
[Are the Types Wrong](https://arethetypeswrong.github.io/?p=memize%402.1.0) is currently reporting errors for memize:
> Problems
>
> * ❌ No types: Import resolved to JavaScript files, but no type declarations were found.
>
>
> ||"memize"
> |---|---|
> |node10 |✅|
> |node16 (from CJS) |❌ No types|
> |node16 (from ESM) |✅ (ESM)|
> |bundler |✅|
For more information, see Are the Types Wrong's [UntypedResolution.md](https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/UntypedResolution.md). Note that the solution is not to point both the CJS and ESM builds at the same `.d.ts` file, for reasons explained in Are the Types Wrong's [FalseESM.md](https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseESM.md). Quoting that page:
> A golden rule of declaration files is that if they represent a module—that is, if they use import or export at the top level—they must represent exactly one JavaScript file. They _especially_ cannot represent JavaScript files of two different module formats.
The easiest solution I found was to run `tsc` a second time to build a `.d.cts` file. For this second invocation, I pointed it at the Rollup-generated `.cjs` file. (This is because tsc and Rollup by default handle default exports differently for CJS files: tsc translates `export default foo` to a `default` attribute on an object with `__esModule: true` and requires that you instead use `export =` for a "true" CommonJS export, while Rollup [by default](https://rollupjs.org/configuration-options/#output-exports) creates a "true" default export. By pointing tsc at the Rollup-generated `.cjs` file, tsc sees Rollup's `export =`.)
* Remove no longer needed `types`
Co-authored-by: Andrew Duthie <[email protected]>
* Remove more redundant `types` entries
Since we follow the default extensions, we shouldn't need to specify `types`.
---------
Co-authored-by: Andrew Duthie <[email protected]>
0 commit comments