Typescript 中命名元组的通用名称是什么?

What the generic name of named tuple in Typescript?

我写了这段代码:

type SomeOptions = {
  a: string;
};

type SomeMethod<T extends any[]> = (
  ...args: [...T, otherOptions: SomeOptions]
) => void;

但 TypeScript 检查器抛出错误:“元组成员必须全部有名称或全部没有名称。”

那么如何将 T 定义为命名元组?

这可能是您想要的:

type SomeOptions = {
  a: string;
};

type SomeMethod<T extends any[]> = (
  ...args: [...pre: T, otherOptions: SomeOptions]
) => void;

type SomeOptions = {
  a: string;
};

type SomeMethod<T extends any[]> = (
  ...args: [...T, SomeOptions]
) => void;