-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Bug: [no-unnecessary-boolean-literal-compare] False positive and unsafe fix with exactOptionalPropertyTypes #9105
Comments
This is actually working as expected. When you intersect two union types the resulting type is the intersection of the unions - i.e. the types that exist in both unions. When you intersect two object types TS will include all the unique properties between the two types, and then it will intersect the common properties. So what you end up with in your example is Which is why you can write When we inspect the types for If you tweak the types slightly you'll see that rules like IDK if the behaviour is correct from TS's side here - surely it should be erroring on the property / saying the type is |
Both members of the intersection have
This does seem like a TypeScript bug.
That shows |
This comment was marked as outdated.
This comment was marked as outdated.
It looks like this is the related TypeScript bug: |
Disregard my comment, didn't realize |
Yes - that's because TS's "intellisense printer" shows you the type AND the context. So when it shows you the context (the property name) it also needs to show the "divider". When it prints the divider it also inspects the flags for the property to determine if it should also print the microsoft/TypeScript#58174 looks to be the culprit - that's why it works without the intersection but breaks it with it. So I'll close this as a bug in TS. |
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.3.2&fileType=.tsx&code=MYewdgzgLgBCAOUCW4IC4YG8YDMA2AhgOYD8GARiCHgKYFgwC%2BMAZFroaRVbfTAD4wArmAAmNHEjA1RTGAF4sjANwAoUJGo0AdHhBEAFAmSpt%2BYgvmKcBPBBoBKNUA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ARhw5IhTWo3yJoQ%2BLTIcAtsRGJ0UJdA7RI4MAF8QZoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEk6AHgIbR64HGOoAKmsiWeAJ4AVQfzKU8mAK7oANOBqQSU5CwpgpsxQF8QOoA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
No errors. I haven’t changed the default options
{ allowComparingNullableBooleansToTrue: true, allowComparingNullableBooleansToFalse: true }
, so comparingboolean | undefined
tofalse
should be allowed.Actual Result
The rule automatically applies an incorrect fix
options.flag === false
→!options.flag
, which changes the output of the code fromfalse
totrue
.Additional Info
No response
The text was updated successfully, but these errors were encountered: