Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor codepaths relying on uncomparable === undefined #59585

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

This could be pushed as part of #59559 and it would fix the self-check there (when combined with #59584 ). I think there it might be easier to review this in isolation though and that changes here (at least most of them) are good regardless of what will happen to #59559

I suspect many of those checks are artifacts of the fact that the codebase is old and originally it was written without strictNullChecks. Some of the changes are more risky than others as there could be some incorrect ! passed to those call sites. I have inspected all of the paths I've touched to derisk this but I'm just a human 😉 The good thing is that the existing tests pass :)

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Aug 10, 2024
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@@ -11,7 +11,7 @@ function verifyMissingFilePaths(missing: ReturnType<ts.Program["getMissingFilePa
const map = new Set(expected);
for (const missing of missingPaths) {
const value = map.has(missing);
assert.isTrue(value, `${missing} to be ${value === undefined ? "not present" : "present only once"}, in actual: ${missingPaths} expected: ${expected}`);
assert.isTrue(value, `${missing} to be ${!value ? "not present" : "present only once"}, in actual: ${missingPaths} expected: ${expected}`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was an actual bug but a very small one (just in the assert's message), and just in the test runner

@jakebailey
Copy link
Member

I think the overall problem with this sort of thing is that a lot of the checks have just changed from a newly-detectable form to a different form we don't check, e.g. typeof ... === ... or assertIsDefined (which I have long wanted to make only accept potentially undefined values).

@Andarist
Copy link
Contributor Author

I agree, the changes to checks that I had to touch bring no value on their own. It's just that those checks are consistently not checked/validated by TS whereas === had a special case for nullable. That is counterintuitive and surprising to users as they are used to the behavior of non-nullable types and they often don't expect this exception.

I don't exactly believe that this alone leads to bugs. People can't strongly rely on those checks. But then the current behavior doesn't help them to catch those bugs that could be prevented with this change in place. From my POV, it's a like a post-factum headscratcher - "why this hasn't been caught by TS? it would yell at me if I would have this seemingly similar line of code!".

And, of course, the checks here had to be only adjusted because the types were imprecise. If this wouldn't be the case then no changes would be required, this PR would only drop redundant code that was discovered in the process. That said, it's unclear to me how to best deal with unchecked indexed accesses here without... noUncheckedIndexedAccess. It feels like mainly the users with this flag could reasonably benefit from this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

3 participants