Typescript 非结构化对象中rest数组的类型

Typescript 非结构化对象中rest数组的类型,typescript,flowtype,Typescript,Flowtype,如何在此处将c注释为任意类型的可选数组 const a = ({ b, ...c }: { b: string, c: ? }) => null 因为这是属性分解,所以它将不是一个数组,而是一个对象: const a = ({ b, ...c }: { b: string, c: object}) => null; 实时非类型脚本示例: const a=({b,…c})=>{ log(“typeof c:,typeof c);//true console.log(“Array.

如何在此处将
c
注释为任意类型的可选数组

const a = ({ b, ...c }: { b: string, c: ? }) => null

因为这是属性分解,所以它将不是一个数组,而是一个
对象

const a = ({ b, ...c }: { b: string, c: object}) => null;
实时非类型脚本示例:

const a=({b,…c})=>{
log(“typeof c:,typeof c);//true
console.log(“Array.isArray(c):”,Array.isArray(c));//false
console.log(JSON.stringify(c));/“{”x:1,“y:2”,z:3}”
};

a({x:1,y:2,z:3})
如您所述,任何类型的可选数组:
c?:数组

const a=({b,c}:{b:string,c?:Array}):void=>null
例如:

const a=({b,c}:{b:string,c?:Array}):void=>{
console.log('b:',b)
if(数组的c实例){
对于(c项中的项目){
console.log('c项:',项)
}
}
}
a({b:'1',c:[1]})
a({b:'1'})
{b,c}:
正在解包,
b
c
都是变量<代码>{b,…c}:是非法声明。
.

你说“可选”是什么意思
c
始终是一个对象。它可能是空的(如果使用除
b
之外没有自己属性的对象调用
a
),但它始终将是一个对象。没错,我的意思是空的。