Commit b77bc39
Fix types for .cjs build (#16)
* 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]>1 parent d461490 commit b77bc39
2 files changed
+13
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
15 | | - | |
| 14 | + | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
0 commit comments