Skip to content
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

Getting "typescript-eslint/unbound-method" using a simple Svelte "on:event" syntax. A false positive? #103

Closed
frederikhors opened this issue Mar 18, 2021 · 6 comments

Comments

@frederikhors
Copy link
Contributor

frederikhors commented Mar 18, 2021

I'm converting to Typescript this code:

<div
  class={"myClass"}
  style={getStyle(someVar)}
  on:animationend={myStore.action}
>

on the line on:animationend={myStore.action} typescript-eslint is complaining about:

Avoid referencing unbound methods which may cause unintentional scoping of this. eslint@typescript-eslint/unbound-method.

What should I do?

Change it to the below? But I like Svelte because of its laconicity!

<!-- I don't like this -->
<div
  class={"myClass"}
  style={getStyle(someVar)}
  on:animationend={(e)=>myStore.action(e)}
>

Can you help me understand, please?

@JounQin
Copy link

JounQin commented Mar 18, 2021

What is myStore.action? It should be just as same as #102.

@Conduitry
Copy link
Member

The rule sounds like it's doing what it's supposed to do. You either need to disable it, or otherwise appease the type checker. This doesn't have anything to do with Svelte.

@frederikhors
Copy link
Contributor Author

@JounQin myStore.action is:

action(event: AnimationEvent | string) {
  // handle event here
},

@Conduitry some hours ago I found something that had to be "correct" in Svelte types. I don't think I'm asking for much but an indication, among other things useful for all those who will look after me.

@JounQin
Copy link

JounQin commented Mar 19, 2021

@frederikhors

Use following like sveltejs/svelte#6094

action(this:void, event: AnimationEvent | string) {
  // handle event here
},

Or arrow function

action: (event: AnimationEvent | string) => {
  // handle event here
},
``

@frederikhors
Copy link
Contributor Author

@JounQin it works! I love you! ❤️❤️❤️

@Conduitry Simply this.

@JounQin
Copy link

JounQin commented Mar 19, 2021

I think you should ready more carefully about the rule itself before raising issues, bro.

https://github.com/typescript-eslint/typescript-eslint/blob/v4.17.0/packages/eslint-plugin/docs/rules/unbound-method.md#rule-details

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants