Skip to content

Commit cf76a4e

Browse files
bilalqtido64
andauthored
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 <[email protected]>
1 parent 0cf9db8 commit cf76a4e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

types/index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ interface AsyncStorage {
6060
}
6161

6262
type AsyncStorageHook = {
63-
getItem(callback?: (error?: Error, result?: string) => void): Promise<string | null>;
64-
setItem(value: string, callback?: (error?: Error) => void): Promise<void>;
65-
mergeItem(value: string, callback?: (error?: Error) => void): Promise<void>;
66-
removeItem(callback?: (error?: Error) => void): Promise<void>;
63+
getItem: (callback?: (error?: Error, result?: string) => void) => Promise<string | null>;
64+
setItem: (value: string, callback?: (error?: Error) => void) => Promise<void>;
65+
mergeItem: (value: string, callback?: (error?: Error) => void) => Promise<void>;
66+
removeItem: (callback?: (error?: Error) => void) => Promise<void>;
6767
}
6868

6969
declare module '@react-native-async-storage/async-storage' {

0 commit comments

Comments
 (0)