Conversation
Are the Types Wrong (https://arethetypeswrong.github.io/?p=%40hapi%2Fhoek%4011.0.4) was reporting the following errors: * Used fallback condition - Import resolved to types through a conditional package.json export, but only after failing to resolve through an earlier condition. This behavior is a TypeScript bug. It may misrepresent the runtime behavior of this import and should not be relied upon. * Masquerading as CJS - Import resolved to a CommonJS type declaration file, but an ESM JavaScript file. This could result in TypeScript errors similar to the following, depending on the specific tsconfig.json options used: > error TS7016: Could not find a declaration file for module '@hapi/hoek'. 'node_modules/@hapi/hoek/lib/index.mjs' implicitly has an 'any' type. > There are types at 'node_modules/@hapi/hoek/lib/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@hapi/hoek' library may need to update its package.json or typings.
|
Shouldn't typescript use this line regardless of the actual file it's going to import? https://github.com/hapijs/hoek/blob/master/package.json#L12 |
|
Reading the article, wouldn't it work having import and require as separate objects like in the last part? |
|
Well, I couldn't reproduce your issue with the condition you provided, and some typescript fixes were done a long while ago in 11.0.4, I see in your issue you're still using 11.0.2, could you try upgrading? |
|
Thank you; I failed to realize I was out of date. 11.0.4 fixes the specific compiler error I was encountering, but the "Masquerading as CJS" issue reported by Are the Types Wrong still exists. To reproduce:
TypeScript will compile without errors, but Node will throw an error at runtime: You could fix this by using separate (I'll also note that this isn't a huge issue - you can avoid it via |
Are the Types Wrong (https://arethetypeswrong.github.io/?p=%40hapi%2Fhoek%4011.0.4) was reporting the following errors:
This could result in TypeScript errors similar to the following, depending on the specific tsconfig.json options used:
To fix it, I simply copied
index.d.tstoindex.d.mts, so both the CJS and ESM versions of the library have types, as described in Masquerading as CJS.Fixes #394