-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Description
Describe the bug
onRowSelectionChange, onSortingChange, onExpandedChange, etc are all expecting a OnChangeFn<T>:
declare type Updater<T> = T | ((old: T) => T);
declare type OnChangeFn<T> = (updaterOrValue: Updater<T>) => void;
Usage works fine when passing in a setState method, but I am struggling to enhance it because typescript believes it's a Value and not a function.
e.g.
// ✅ TS is happy with setSorting
const [sorting, setSorting] = useState<SortingState>([]);
// ✅ TS is happy with handleMultiColumnSortconst
handleMultiColumnSort = (state: Updater<SortingState>) => {
// ❌ When logging state we see it is a function
// when trying to call it though, typescript throws an error:
console.log('state', state?.());
};
Typescript error:
This expression is not callable.
Not all constituents of type 'Updater<SortingState>' are callable.
Type 'SortingState' has no call signatures.ts(2349)
Your minimal, reproducible example
https://codesandbox.io/s/xenodochial-herschel-zlq6y9?file=/src/main.tsx
Steps to reproduce
- Go to sandbox and open the console in codesandbox
- Click on any header, notice the function and actual object logs
- Go to ln 91+ to see the issue
Expected behavior
If state is a function, typescript should show the correct type
How often does this bug happen?
No response
Screenshots or Videos
No response
Platform
OS: macOS
react-table version
8.5.31
TypeScript version
v4.6.3
Additional context
No response
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
ahmadichsan, gyeongmin-lee, zyzski, mzaharie, Noyabronok and 1 more
Metadata
Metadata
Assignees
Labels
No labels