Repository navigation
[utils] Integrate "Are the Types Wrong", and fix issues #10203
Description
Activity
- changed the title
[-]Integrate `@arethetypeswrong/cli`[/-][+]Integrate "Are the Types Wrong", and fix issues[/+]on Mar 5, 2024 @Mrtenz I ran into this tool when researching
superstruct. Any thoughts on this?Interesting. Is there a difference between CJS and ESM type declarations?
I think the fallback conditions will be resolved when we bump to TypeScript >=5.
Node 10 support for the
/nodeexport seems irrelevant. We could add a file to the root of the project to support it, but Node 10 has been deprecated for a long time. Any currently active versions supportpackage.jsonexports.Reacted by Elliot WinklerJust tested with TypeScript 5.3 and it still says "Used fallback condition". Not sure why that happens.
Ah, I just remembered. The order of exports matters. If you move
typesto the top, it results in:┌───────────────────┬────────────────────────┬────────────────────────┬────────────────────────────────┐ │ │ "@metamask/utils" │ "@metamask/utils/node" │ "@metamask/utils/package.json" │ ├───────────────────┼────────────────────────┼────────────────────────┼────────────────────────────────┤ │ node10 │ 🟢 │ 💀 Resolution failed │ 🟢 (JSON) │ ├───────────────────┼────────────────────────┼────────────────────────┼────────────────────────────────┤ │ node16 (from CJS) │ 🟢 (CJS) │ 🟢 (CJS) │ 🟢 (JSON) │ ├───────────────────┼────────────────────────┼────────────────────────┼────────────────────────────────┤ │ node16 (from ESM) │ 🎭 Masquerading as CJS │ 🎭 Masquerading as CJS │ 🟢 (JSON) │ ├───────────────────┼────────────────────────┼────────────────────────┼────────────────────────────────┤ │ bundler │ 🟢 │ 🟢 │ 🟢 (JSON) │ └───────────────────┴────────────────────────┴────────────────────────┴────────────────────────────────┘Reacted by Elliot WinklerAh that's interesting!
I realized I didn't answer this question:
Is there a difference between CJS and ESM type declarations?
I think so, yes. I think all imports in ESM type declarations need to end in
.js. This could be why it's saying "masquerading as CJS". But I will look into that.Running
tscwith--module es2020doesn't add extensions to the imports. We could use thedtsoption oftsup, which would output ad.mtsand.d.tsfile with appropriate imports. This doesn't work for monorepos though, sincetsupdoesn't support TypeScript project references.Gave it a try here: MetaMask/utils#178.
attwfails because thenodeexport doesn't work with <Node16. We may need to run it twice if we want to do it automatically in CI. Once for the main export andpackage.json, and once for thenodeexport with <Node16 disabled.Reacted by Elliot Winkler- changed the title
[-]Integrate "Are the Types Wrong", and fix issues[/-][+][utils] Integrate "Are the Types Wrong", and fix issues[/+]on Sep 11, 2026
Are the Types Wrong? is a tool that scans a library and highlights potential issues with importing it via Node, CommonJS, and ESM.
Running this tool against
@metamask/utilsshows the following report:This tool comes with a CLI which we can run manually to see these issues. We can also add it as a lint step in CI to verify that we don't have any issues going forward.
Once we've update this library so that it passes the above checks, we can copy any changes which are necessary to the module template and apply them to every other library.