'Tuple type in rest arguments can not downcast?

type Func<T extends Record<string, any>> = (
  ...args: {
    [K in keyof T]: [item: T[K], key: K, map: T];
  }[keyof T]
) => void;

The Func type can only accpect (item,key,map)=>void,but can't accpect (item)=>void or (item,key)=>void. How to solve this problem?



Solution 1:[1]

You could use optionals to allow fewer values in the tuple as follows:

type Func<T extends Record<string, any>> = (
  ...args: {
    [K in keyof T]: [item: T[K], key?: K, map?: T?];
  }[keyof T]
) => void;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1