在获取处理typescript的reduce函数时遇到了一些困难-类型和返回值-省略了故事书中的一些控件(在标记为ERROR的代码中添加了两个TS错误)
有人能告诉我正确的解决方案吗?我如何删除这些消息?
const controlsToOmit: string[] = [
'connectedLeft',
'connectedRight',
];
interface Props {
accumulator: {
[key: string]: {
table: {
disable: true;
};
};
};
value: string;
}
const controlsToOmitArgTypes = controlsToOmit.reduce<Props>(
(accumulator, value) => ({
...accumulator,
[value]: {
table: {
disable: true,
},
},
}),
{} ** Argument of type '{}' is not assignable to parameter of type 'Props' **
);
export default {
title: 'Components/Buttons/ButtonMeta',
component: ButtonMetaComponent,
argTypes: {
...controlsToOmitArgTypes, ** Spread types may only be created from object types. **
},
};
controlsToOmitArgTypes
返回以下对象
{
"connectedLeft": {
"table": {
"disable": true
}
},
"connectedRight": {
"table": {
"disable": true
}
},
}
1条答案
按热度按时间2vuwiymt1#
reduce
的类型参数用于指示返回类型您需要返回如下结构:
第一个