Commit cf76a4e
fix(types): remove 'this' binding expectations on hook fn types (#736)
* feat(types): set void as this type of hook fns
This change improves the experience for TypeScript users that have the
[`unbound-method`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/unbound-method.md)
rule enabled. Without this change, check failures occur when users
attempt to use destructured references to the functions returned in the
`useAsyncStorage` hook's envelope object.
Example:
```typescript
const { getItem, setItem } = useAsyncStorage('someKey')
// eslint@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.
```
* chore: define hook types with arrow fns
This approach achieves the same end result as explicitly declaring the `this` type to be void and is more familiar to readers who know JS.
Co-authored-by: Tommy Nguyen <4123478+tido64@users.noreply.github.com>1 parent 0cf9db8 commit cf76a4e
1 file changed
+4
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
0 commit comments