Comments (6)
The rule is never aware that a method is able to bind the this
value, because it never knows. Otherwise, you have to special-case a lot of array methods too.
from typescript-eslint.
Josh is correct - the rule is purposely shallow in how it reports on usage. It does not understand the inner workings of function calls - even those in the stdlib. Mostly because the complexity of building out support for all of the various forms that are safe is large and expensive and ultimately not worth the cost - both maintenance cost and runtime cost - given that such usecases are super rare in the general case.
Eg most people don't use the Reflect
API because is relatively new and in particular Reflect.apply
is really no better than the more direct method.apply
.
I'm okay with the rule not handling these cases. If we want to document the edge case, we can?
from typescript-eslint.
Thanks for the response - I largely agree with you, I wasn't even sure if it's worth reporting.
Still want to leave here my implementation idea just in case there's any demand for covering such use case:
- Only check static method usages, for example
Reflect.apply
,Array.prototype.map.call(...)
and notsomeVar.map(...)
(but perhaps<array literal>.map(...)
? - Make this check opt-in if it runtime costly.
from typescript-eslint.
This rule already relies on type information, so checking someVar.map
is not any harder than Reflect.apply
, because we can use type information to know that someVar
is an Array
. The only problem is whether it's worthwhile to do so because we tend to not like carving special cases for built-in functions.
Maybe we need some generic way to exempt methods from being checked (or declare that they have a thisArg
parameter), and add these built-ins as default options? Sounds really complicated to do right, though. Again, I don't really think this happens that often now.
from typescript-eslint.
The only problem is whether it's worthwhile to do so
My vote is that it's not.
The number of people that use that "this" arg is so, so, so low. "this" meta programming went out of style with TS cos it's a PITA to safely write.
The cost of writing the code plus the (negligible) cost at runtime just isn't worth it to catch an 0.0001% case, IMO.
from typescript-eslint.
I'm +0.8 on what Brad said, the rest 0.2 of reservation comes from me being a part time JavaScript Ninja that likes "obscure" patterns.
from typescript-eslint.
Related Issues (20)
- Enhancement: Display tsconfig errors in playground
- [consistent-type-imports] ignores `TSTypeReference` reports false positive for "used by decorator metadata" HOT 2
- Bug: [no-useless-template-literals] Nested template literals contain useless one
- Bug: [no-base-to-string] false positive on template literal type from external typings HOT 4
- Docs: Add links to Contributing page HOT 1
- Docs: Add section for troubleshooting "Definition for rule x was not found" when doing Local Linking HOT 8
- Bug: allowAutomaticSingleRunInference not working in pnpm repository HOT 2
- Bug: @typescript-eslint/no-unsafe-assignment doesn't work with multiple casts HOT 1
- Enhancement: [consistent-return] handle calls to `never` returning functions HOT 2
- Bug: [no-unnecessary-template-expression] Report squigglies should underline template syntax, not just expression inside HOT 7
- Rule proposal: prefer-readonly-interface HOT 1
- Bug: *-type-checked-only configs are not exported HOT 2
- Bug: [@typescript-eslint/array-type] <Definition for rule '@typescript-eslint/array-type' was not found> HOT 1
- Repo: Integration tests failing on main due to upstream eslint-stylistic changes
- Repo: Either file an issue when integration tests fail on main, or pin and auto-update its dependencies HOT 4
- Bug: [no-base-to-string] Maps result in [object Map] not [object Object] HOT 12
- Bug: rules from `@typescript-eslint/eslint-recommended` cannot be applied to files with custom file extensions HOT 12
- Rule proposal: Warn on functions with consecutive parameters of the same type
- Bug: [no-useless-template-literals] Comments are removed by auto-fix HOT 3
- Docs: Explicitly say whether PR authors should merge from `main` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript-eslint.