[英]Binding element "some test text" implicitly has an "any" type
I´ve got problem with TS compiler, It throws me this error: Binding element " " implicitly has an "any" type.我遇到了 TS 编译器的问题,它向我抛出了这个错误:绑定元素“”隐式具有“任何”类型。
The error is occured at the map function and for the attributes (id, title, action, backgroundColor, color).错误发生在 map 函数和属性(id、title、action、backgroundColor、color)上。
Below is my code:下面是我的代码:
export type MessageWindowComponentProps = PropsWithChildren<{
readonly buttonsType: ButtonsType,
readonly saveText: string,
readonly closeText: string,
readonly yesText: string,
readonly noText: string,
readonly onSaveClick?: () => void;
readonly onCloseClick?: () => void;
readonly onYesClick?: () => void;
readonly onNoClick?: () => void;
}>
const classNames = bemClassNames("message-window");
const messageWindowContent = classNames("content");
const messageWindowButtons = classNames("buttons");
export const MessageWindowComponent: FunctionComponent<MessageWindowComponentProps> = ({
children,
buttonsType,
saveText,
closeText,
yesText,
noText,
onSaveClick,
onCloseClick,
onYesClick,
onNoClick,
}) => {
const typeOfButtons = {
[ButtonsType.yesNo]: [
{id: 1, title: {noText}, action: onYesClick, backgroundColor: ButtonBackgroundColor.whitePrimaryFixed, color: TextColor.textPrimary},
{id: 2, title: {yesText}, action: onNoClick, backgroundColor: ButtonBackgroundColor.colorPrimary, color: TextColor.whiteBlack},
],
[ButtonsType.saveClose]: [
{id: 3, title: {closeText}, action: onCloseClick, backgroundColor: ButtonBackgroundColor.whitePrimaryFixed, color: TextColor.textPrimary},
{id: 4, title: {saveText}, action: onSaveClick, backgroundColor: ButtonBackgroundColor.colorPrimary, color: TextColor.whiteBlack},
],
[ButtonsType.close]: [
{id: 5, title: {closeText}, action: onCloseClick, backgroundColor: ButtonBackgroundColor.colorPrimary, color: TextColor.whiteBlack},
],
};
return (
<div className={classNames()}>
<div className={messageWindowContent}>
{children}
</div>
<div className={messageWindowButtons}>
<Layout justifyContent={JustifyContent.flexEnd}>
{typeOfButtons[buttonsType].map(({id, title, action, backgroundColor, color}) => (
<Layout key={id} spacingSizeLeft={SpacingSize.s}>
<TextButton backgroundColor={backgroundColor} color={color} shadow={false} onClick={action ?? doNothing} text={title} title={title} />
</Layout>
))}
</Layout>
</div>
</div>
);
};
Thank you for your help.感谢您的帮助。
Compiler suggests that typeOfButtons does not have specified type.编译器建议typeOfButtons没有指定类型。 Just add a type to this variable and it should be ok.
只需为这个变量添加一个类型,它应该没问题。 Also check what type is ButtonsType is so you can put that type inside of a typeOfButtons type definition.
还要检查ButtonsType是什么类型,以便您可以将该类型放入typeOfButtons类型定义中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.