-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enhancement: [no-unsafe-*] misses any
violations on union and object types
#10158
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
Comments
any
violations on unions and objects typesany
violations on unions and objects types
any
violations on unions and objects typesany
violations on union and object types
Adding that functions are also being missed: declare const onSomething: (callback: () => number) => void;
declare const callback: () => any;
// no lint errors
onSomething(callback); |
The rules currently do not recurse into cases like arguments, return types, or sub-union members - for complexity reasons on the initial implementation and generally these cases are caught at the declaration site. Eg the return type issue should be handled at the function declaration via Usually the only time you'd be dealing with such cases like these is if an external library type has given them to you. Do you have a real-world example of this that a combination of all of the current |
Yes, @bradzacher, I agree that this error will usually pop up if you use a badly typed external library (though I'll be happy to catch those too). I didn't encounter a real-world example; this mostly started as a discussion at #10051 (comment). Out of curiosity, I did write a rough implementation of this and ran it on I'll add that on my (potentially faulty) implementation, the time it takes to lint I don't know if this is worth the extra complexity and time the rule will take to execute (time can probably be improved though). |
The extra time would be because all type information is computed lazily - the more you access, the more that gets computed. So by going deeper into the inspections of things it doesn't surprise me that the rule gets slower! |
Tempting, but I'm not in favor. I get the appeal of more deeply checking for |
I like having rules be as strict as they can be, but I agree that fringe examples aside, it's not worth the extra complexity and the performance hit. The issue has been open for just over two and a half months with no community reactions. I think it can be closed π |
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=PTAEDsHsFoFdwM4EMBmBTaSBOBzWBbNcAFwC4AocgEzQGMAbbNUWyRY0JU0Ab1BUiRuScAE9QAXwDclFPFrEAlm36CAFAA9ufAUNAJiWReBySAlNtV6DRk5N7lQoLGmKws4UBpkTKIUACqiKjM2HiEJKCQKKDEogAOzAAGOoLCYlKSSZwICIo44GhUsZCcoPHYSITEaFhRMXGJoClW3DbGOJkSSQB05LpqSGYy1HSMLixsBqAARumiANoAuqAAPhAEM7UjcuAKyp4z2Jpthh3Laxv4W1gW%2BmcmF%2Bvgm7UOTi5uHl4%2BfmBByHQnFwBCIHGisQSyRe1ze6xEiyW2SQuXyhWKxFKSHKlWqbwhjWhrzq63ajyRfSOWDUM2Gf30inwinG9HEAHdFMQABbNKBwYLoaCfdzgJKUGgMJiTdgsSy6eaSEZoDTxSBYDi7fYqLloej0SBqO6pawPUwSd6gfwAkLOVwi%2BqQppJBHZFBYSD4fjyJQqDnc21fTyE5pknC9RwB%2B1IX6jSUTVgyqjzJ5XG5KlVqjXeg6gNlq%2BhUQ2nWw4FMwm4Wq0C5jC74EqHNBHLV3uz2an2eP082tBhtJUPNvofO3fGY%2BIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tieQEMAZolp9kySgHMmAW0Qt0URNGgdokADThseIqWQVqdBszaduvQcOiJ8saEwWQlKtVoC%2BIN0A&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
I expected the rule to fail on these, similarly to how it fails on similar boxed values like
Promise<any>
, orany[]
, along with a combination of boxed values.Actual Result
The code example is reporting no lint errors.
Additional Info
The
no-unsafe-*
rule family misses some edge case checks, mostly around boxed values (like arrays, objects, promises, etc.). While you get a warning for mostany
values wrapped in a box, I found some the rule misses around union and object types.I made a simplified implementation to test-run on typescript-eslint's own repo and found one issue here (matching
string[] | undefined
withany[]
).The text was updated successfully, but these errors were encountered: