Related Zod issue: colinhacks/zod#5686
The README states regarding always using cts:
This warning does not cause any resolution issues (unlike "Masquerading as ESM"). Technically, we're tricking TypeScript into thinking our code is CommonJS; when in fact it may be ESM. The ATTW tool is very rigorous and flags this; in practice, this has no real consequences and maximizes compatibility (Zod has relied on the CJS masquerading trick since it's earliest days.)
I believe this may no longer be true. Now that TypeScript has pushed for module writers to use nodenext module type, there is a real consequence for "masquerading as CJS" when operating in an ESM environment. TypeScript assumes the default export of a CJS always contains the entire module.exports, which means it will reference things like z.z.core.$strip in the declaration file that are incorrect. This causes breaking behavior when packages compiled with one module type are used in a TS environment with another (e.g. nodenext vs esnext).
The workaround is to never use the default export from a zshy package in ESM code, but that requires special enforcement/lint rules.
Related Zod issue: colinhacks/zod#5686
The README states regarding always using
cts:I believe this may no longer be true. Now that TypeScript has pushed for module writers to use
nodenextmodule type, there is a real consequence for "masquerading as CJS" when operating in an ESM environment. TypeScript assumes the default export of a CJS always contains the entiremodule.exports, which means it will reference things likez.z.core.$stripin the declaration file that are incorrect. This causes breaking behavior when packages compiled with one module type are used in a TS environment with another (e.g.nodenextvsesnext).The workaround is to never use the default export from a
zshypackage in ESM code, but that requires special enforcement/lint rules.