Typescript 如何允许未知类型的变量函数参数

Typescript 如何允许未知类型的变量函数参数,typescript,Typescript,假设我有这个代码: 接口A{ doSomething?:使用上述方法。您是否尝试过以下方法: interface A<T> { doSomething?: (...args: T[]) => void; } type B = {a: {b: {c: string}}}; const a = ({a: {b:{ c}}}: B) => console.log(c); const AA: A<B> = { doSomething: a //Type

假设我有这个代码:

接口A{

doSomething?:使用上述方法。

您是否尝试过以下方法:

interface A<T> {
  doSomething?: (...args: T[]) => void;
}

type B = {a: {b: {c: string}}};

const a = ({a: {b:{ c}}}: B) => console.log(c);

const AA: A<B> = {
  doSomething: a //Type 'unknown[]' is not assignable to type '[B]'.
                 //  Target requires 1 element(s) but source may have fewer.
}
接口A{
doSomething?:(…args:any[])=>void;
}
类型B={a:{B:{c:string}};
常量a=({a:{b:{c}}}:b)=>console.log(c);
常数AA:A={
doSomething:a//类型“unknown[]”不可分配给类型“[B]”。
//目标需要1个元素,但源的元素可能较少。
}

您也可以考虑使用如下的泛型类型:

interface A<T> {
  doSomething?: (...args: T[]) => void;
}

type B = {a: {b: {c: string}}};

const a = ({a: {b:{ c}}}: B) => console.log(c);

const AA: A<B> = {
  doSomething: a //Type 'unknown[]' is not assignable to type '[B]'.
                 //  Target requires 1 element(s) but source may have fewer.
}
接口A{
doSomething?:(…args:T[])=>void;
}
类型B={a:{B:{c:string}};
常量a=({a:{b:{c}}}:b)=>console.log(c);
常数AA:A={
doSomething:a//类型“unknown[]”不可分配给类型“[B]”。
//目标需要1个元素,但源的元素可能较少。
}