Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed as not planned
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I havesearched for related issues and found none that matched my issue.
- I haveread the FAQ and my problem is not listed.
Playground Link
Repro Code
exportconstenumTypeFlags{Any=1<<0,Unknown=1<<1,String=1<<2,Number=1<<3,Boolean=1<<4}exportfunctionhasTypeFlag(source:TypeFlags,target:TypeFlags){return(source&target)===target;}
ESLint Config
module.exports={"rules":{"@typescript-eslint/no-unsafe-enum-comparison":"error"}}
tsconfig
{"compilerOptions": {"strictNullChecks":true }}Expected Result
TypeScript compiler is using bit mask pattern internally. It is rare, but useful thing. A bitwise operator is used in comparison, but otherwise enum is compared with itself. Should this be allowed or at least have a config option, perhaps? What do you think?
Also possible to rework the code. It felt more readable with===, but could be like this too:
exportfunctionhasTypeFlag(source:TypeFlags,target:TypeFlags){returnBoolean(source&target);}
Actual Result
Good idea to add theno-unsafe-enum-comparison. As you can see in reproduction, currently it does not work with bit mask pattern. Might be it was simply overlooked use case.
Additional Info
No response