Why do I get "Avoid referencing unbound methods which may cause unintentional scoping of `this`. eslint@typescript-eslint/unbound-method" in this case?
See original GitHub issueI’m using Svelte 3, Typescript and this code:
- loginStore.ts:
import { writable } from "svelte/store";
const store = () => {
const state = {
isLoggedIn: false,
};
const { subscribe, update } = writable(state); // warning: Avoid referencing unbound methods which may cause unintentional scoping of `this`. eslint@typescript-eslint/unbound-method (2 times)
const methods = {
OnInit() {
this.Login(); // warning: Unsafe member access .Login on an any value. eslint@typescript-eslint/no-unsafe-member-access and another warning: Unsafe call of an any typed value. eslint@typescript-eslint/no-unsafe-call
},
Login() {
if (window.localStorage.isLoggedIn) {
update(() => {
state.isLoggedIn = true;
return state;
});
}
},
async Logout() {
await doLogout();
update(() => {
state.isLoggedIn = false;
return state;
});
},
};
return {
subscribe,
...methods,
};
};
export default store();
But @typescript-eslint is giving me these errors:
-
Avoid referencing unbound methods which may cause unintentional scoping of this2 times on line:const { subscribe, update } = writable(state) -
Unsafe member access .Login on an any valueon line:this.Login() -
Unsafe call of an any typed valueon line:this.Login()
How can I fix these warnings?
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (10 by maintainers)
Top Results From Across the Web
Avoid referencing unbound methods which may cause ...
angular - Avoid referencing unbound methods which may cause unintentional scoping of `this` error when calling static methods - Stack Overflow. ...
Read more >unbound-method | typescript-eslint
Enforce unbound methods are called with their expected scope. ... This rule reports when a class method is referenced in an unbound manner....
Read more >no-unbound-method - Rule
Warns when a method is used outside of a method call. Rationale. Class functions don't preserve the class scope when passed as standalone...
Read more >JS-0387 · Prefer that unbound methods are called with their ...
Avoid referencing unbound methods which may cause unintentional scoping of this . If your function does not access this , you can annotate...
Read more >Avoid referencing unbound methods which may cause ...
[Solved]-Avoid referencing unbound methods which may cause unintentional scoping of `this` error when calling static methods-angular.js · turn off this lint rule ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
No, that’s up to the user to decide how strict he wants his type checking.
I can close this. You people are wonderful people!