简体   繁体   English

绑定元素“一些测试文本”隐式具有“任何”类型

[英]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.

相关问题 TypeScript 错误:“元素隐式具有 'any' 类型,因为类型 'any' 的表达式不能用于索引类型 - TypeScript Err: "Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 元素隐式具有“任何”类型,因为“_popupComponentRef”类型的表达式不能用于索引类型“MatDatepicker”<Date> &#39; - Element implicitly has an 'any' type because expression of type '"_popupComponentRef"' can't be used to index type 'MatDatepicker<Date>' TS 7015:元素隐式具有“任何”类型,因为索引表达式不是 Object 的“数字”类型。getElementsByTagName 的键 - TS 7015: Element implicitly has an 'any' type because index expression is not of type 'number' for Object.keys of getElementsByTagName TS7053:元素隐式具有“任何”类型,因为类型“字符串”的表达式不能用于索引类型“对象” - TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Object' Selenium:测试元素是否包含一些文本 - Selenium: test if element contains some text 输入元素,“文本”类型,标签中没有文本 - input element, type of "text", has no text in label React TS 中的进度条创建 - 尽管在接口中声明了类型,但隐含的错误类型为“任何” - Progress Bar creation in React TS - getting error implicitly has type 'any' although types are declared in interface 测试具有输入类型文本的元素是否存在jquery - Test if element with an input type text exists jquery 无法拖放任何链接<a href>到</a><a href><input type="text"></a><a href>如果某个链接已经粘贴到</a><a href><input></a><a href>前</a> - Can't drag and drop any link <a href> to the <input type="text"> if some link has been already pasted to the <input> before XPath提取元素(如果其子元素中有一些文本) - XPath to extract element if one of its children has some text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM