export default function hi(name: string) {
console.log(`hi ${name}!`)
}
Array.isArray(keyOrKeys) && typeof valueOrIterator === 'function'
type DispatchKey<T> = keyof T;
type DispatchValue<T> = T[DispatchKey<T>];
type InitialState<T> = T | (() => T);
interface Dispatch<T> {
(keyOrKeys: DispatchKey<T>, valueOrIterator: DispatchValue<T>): void;
(keyOrKeys: (DispatchKey<T>)[], valueOrIterator: (key: DispatchKey<T>) => DispatchValue<T>): void;
}
// ...
const dispatch: Dispatch<T> = (keyOrKeys, valueOrIterator) => {
if (Array.isArray(keyOrKeys) && typeof valueOrIterator === 'function') {
setState((prev) => {
const updated = keyOrKeys.map((key) => valueOrIterator(key));
console.log(updated);
return prev;
});
} else {
setState((prev) => ({
...prev,
[keyOrKeys]: valueOrIterator,
}));
}
};