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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悶 Update types to prevent @typescript-eslint/unbound-method errors #360

Open
1 task done
reify-tanner-stirrat opened this issue Jul 27, 2023 · 4 comments 路 May be fixed by #361
Open
1 task done

馃悶 Update types to prevent @typescript-eslint/unbound-method errors #360

reify-tanner-stirrat opened this issue Jul 27, 2023 · 4 comments 路 May be fixed by #361
Assignees
Labels
bug A verified and reproducible bug. triage Has not been reviewed yet and should not be worked on.

Comments

@reify-tanner-stirrat
Copy link

reify-tanner-stirrat commented Jul 27, 2023

What happened?

const { activate } = useIdleTimer(config);

The above will throw:

@typescript-eslint/unbound-method: Avoid referencing unbound methods which may cause unintentional scoping of `this`. If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead.

According to this stackoverflow post, it's because there's a meaningful difference between:

type IIdleTimer = {
  activate(): bool;
}
// and
type IIdleTimer = {
  activate: () => bool;
}

which is that the former is typed as a function() definition and carries the this weirdness, where the latter is not.

Reproduction Steps

See above

Relevant log output

N/A

Screenshots or Additional Context

No response

Module Version

5.7.2

What browsers are you seeing the problem on? Select all that apply.

No response

What devices are you seeing the problem on?

No response

Verification

  • I have checked for existing closed issues and discussions.
@reify-tanner-stirrat reify-tanner-stirrat added bug A verified and reproducible bug. triage Has not been reviewed yet and should not be worked on. labels Jul 27, 2023
@SupremeTechnopriest
Copy link
Owner

Nice catch! Out of curiosity, is this popping up for you because you are using class components?

@reify-tanner-stirrat
Copy link
Author

Nope, normal functional components defined as arrow functions. To be honest I don't understand enough about typescript to understand why it's complaining about this.

@SupremeTechnopriest
Copy link
Owner

Are you using this? No worries I'll look into it.

@reify-tanner-stirrat
Copy link
Author

Nope. I also opened #361 to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A verified and reproducible bug. triage Has not been reviewed yet and should not be worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants