【发布时间】:2020-07-27 09:29:10
【问题描述】:
我有一个类型为 Array<any> 的函数构建的对象数组,并且只想在 forEach 循环中使用部分键。更
打字稿中精确、正确的编码以提供类型?
什么是在打字稿中编码的正确方法,我可以使用forEach(xxx:any),但我想使用像解构对象一样
export function customFunc(...arrays: Array<any>){
return arrays
}
export type PersonTypes = {
name: string;
value: string;
gender: boolean;
};
const people = [
...customFunc([{name: 'apl', value: 'apple', gender: true},
{name: 'gal', value: 'google', gender: false},])
]
people.forEach(person => {
person.forEach(({name, gender})=>{
### how to provide type with destructure object with error Binding element 'name' implicitly has an 'any' type
console.log(name);
console.log(gender);
});
});
【问题讨论】:
标签: typescript typescript-typings typescript2.0 typescript1.8