Giter Site home page Giter Site logo

Comments (6)

Josh-Cena avatar Josh-Cena commented on June 15, 2024 1

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.

bradzacher avatar bradzacher commented on June 15, 2024 1

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.

andreww2012 avatar andreww2012 commented on June 15, 2024

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 not someVar.map(...) (but perhaps <array literal>.map(...)?
  • Make this check opt-in if it runtime costly.

from typescript-eslint.

Josh-Cena avatar Josh-Cena commented on June 15, 2024

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.

bradzacher avatar bradzacher commented on June 15, 2024

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.

Josh-Cena avatar Josh-Cena commented on June 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.