Add a failing test case with types: null condition#54096
Add a failing test case with types: null condition#54096Andarist wants to merge 1 commit intomicrosoft:mainfrom
types: null condition#54096Conversation
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
| @@ -0,0 +1,28 @@ | |||
| error TS6504: File '/node_modules/foo/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? | |||
There was a problem hiding this comment.
i'm not sure how to avoid this in the test setup without allowJs: true (which I would prefer to avoid here).
| ==== /a.ts (0 errors) ==== | ||
| export { a } from "foo"; |
There was a problem hiding this comment.
I feel like this should error because of the quite explicit types: null declaration in the package
|
I agree that this is #50762 which makes it a bug, and I agree that it’s narrow enough to be fixable on its own, and at first glance at the conversation at discordjs/discord.js#9485 it even feels useful. But thinking about it a bit more, it feels a little suspicious to try to forbid usage of a package subpath by derailing TypeScript specifically. In my view, TypeScript’s job is to know how the runtime/bundler is going to resolve, and then to find types for the implementation file the runtime/bundler finds. Sometimes, though, you need to sacrifice a bit of the former in service of the latter—that is, if your types aren’t colocated with implementation files, you grab TypeScript with the |
|
Yeah, I overall agree with you - it's fishy to disallow something by disallowing However, because of the "used fallback condition" bug it didn't actually end up being forbidden there and even a more explicitly expressed intent ( This particular PR is more about the fact that this should work and not as much about if it should be used 😉 |
|
It's also very likely that this particular manifestation of this bug makes weird combinations to behave incorrectly, like |
|
Do you want to see what the narrow fix for this would look like? If we don’t have to jump through hoops to fix |
Do I want to? Not really. Will I investigate this? Yeeeah, that's very likely. |
|
I’m going to steal this PR and fix it |
|
Suppose you have // @Filename: /a/b/c/node_modules/foo/package.json
{
"exports": {
".": {
"types": null
}
}
}and // @Filename: /a/b/c/node_modules/@types/foo/package.json
{
"exports": {
".": {
"types": "./index.d.ts"
}
}
}Should the former block the latter? Should the former block a lookup in a higher-up node_modules directory? |
|
Yes. The first matched location like this should stop the algorithm from looking any further. I’d probably extend this to just any condition (not just to |
|
I think this has some fairly unintuitive semantics. If you want to tell TypeScript that something is explicitly not typed... you can point I think this interpretation is perfectly consistent... it just struck me as weird. Implementation-wise, we actually have no existing mechanism to abort resolution with a failure. Sigh. |
|
@andrewbranch - Are you still attempting to fix this? If I understand this thread correctly, I have what I would consider a similarly narrow issue. I am attempting to "hide" a subset of modules when using a custom "browser" condition. Would it make sense to create a new issue? lib package.json: consuming browser app tsconfig.json: |
|
Planning to fix this as a breaking change in 6.0 or 6.5, depending on whether it needs a deprecation message; I’m not sure we have the details settled. |
|
I'm pretty sure this will fail CI because the behavior changed for the better in #62483, which includes relevant tests. I just wanted to see before closing it permanently. |

This is a test case related to this bug: #50762 .
It feels that this situation is specific-enough to be fixable regardless of what is decided for #50762 , cc @andrewbranch