This is related to this issue on the TypeScript repo:
The tl;dr is that when using a moduleResolution of NodeNext, we are seeing the following error:
error TS2742: The inferred type of 'baz' cannot be named without a reference to '../node_modules/foo/bar/baz'. This is likely not portable. A type annotation is necessary.
I'm pretty sure I understand why this error is happening based on some of the issues filed and in reading documentation. However, what I don't understand is why this is working with a module resolution of Node.
From what I understand, when using NodeNext, TypeScript uses Node's ESM resolution algorithm to find modules. In addition, it also uses the export map provided by exports in package.json. When using Node, it falls back to Node's standard CJS resolution and instead looks at the main and types properties in package.json.
But our main and types properties are exposing the same entrypoints and declaration files that our export map is. I understand that ESM resolution is going to follow a totally different code path than CJS, but why is CJS able to find this inferred type, but ESM is not? Or is it that CJS can't find it either, TypeScript just doesn't warn you with TS2742?
The reason I'm asking is because we're trying to fix this issue in a published package of ours and I don't want to just rush to expose this type if there's a better explanation and course of action to fix it.