TS7031: Binding element ‘role‘ implicitly has an ‘any‘ type.

简介: TS7031: Binding element ‘role‘ implicitly has an ‘any‘ type.

前言

✨✨ 他们是天生勇敢的开发者,我们创造bug,传播bug,毫不留情地消灭bug,在这个过程中我们创造了很多bug以供娱乐。

前端bug这里是博主总结的一些前端的bug以及解决方案,感兴趣可以看一下,有不同方案可以在评论区提出


正文开始

错误场景

React18+ts+vite中我写了一个传入不同参数 实现不同组件的切换的效果


ts定义的时候大家经常出现的问题

问题分析

我的role参数具有隐士的any


const One = ()=><div> I am One</div>
const Two = ()=><div> I am two</div>
const Tree = ()=><div> I am tree</div>
function ReadRole({ role }){
    if(role === "one"){
        return <One></One>
    }else if(role === "two"){
        return <Two></Two>
    }else{
        return <Tree></Tree>
    }
}
const View = ()=>{
    return(
        <div className="sonPage1">
            我是sonPage1
            <ReadRole role={"one"}></ReadRole>
        </div>
    )
}
export default View;

解决方案

指定为显示数据类型



后言

创作不易,要是本文章对广大读者有那么一点点帮助 不妨三连支持一下,您的鼓励就是博主创作的动力


目录
相关文章
|
Java 数据库连接 mybatis
mybaits报错:The content of element type “resultMap“ must match “(constructor?,id*,result*,associati。。。
mybaits报错:The content of element type “resultMap“ must match “(constructor?,id*,result*,associati。。。
552 0
|
6月前
|
JavaScript
Vue报错 Invalid default value for prop “list“: Props with type Object/Array must use a factory
Vue报错 Invalid default value for prop “list“: Props with type Object/Array must use a factory
320 0
|
5月前
Each child in a list should have a unique “key“ prop. Check the render method的报错解决
Each child in a list should have a unique “key“ prop. Check the render method的报错解决
【已解决】Error: Element type is invalid: expected a string (for built-in components) or a class/function
Error: Element type is invalid: expected a string (for built-in components) or a class/function
2550 0
【已解决】Error: Element type is invalid: expected a string (for built-in components) or a class/function
Property ‘Authorization‘ does not exist on type ‘HeadersDefaults‘
Property ‘Authorization‘ does not exist on type ‘HeadersDefaults‘
88 0
|
Java
【ES异常】mapper [sortNum] of different type, current_type [long], merged_type [keyword]
【ES异常】mapper [sortNum] of different type, current_type [long], merged_type [keyword]
143 0
Unknown custom element: <add-employee> - did you register the component correctly? For red cursive c
原因: 1.组件名没写对(导入和注册不对应) 2.components少写了个s 3.组件命名最好是驼峰命名 4.导入时语法错误 5.代码中有两个components,后一个的值把前一个覆盖了 6.组件直接循环套用了
Warning: [antd: Form.Item] `defaultValue` will not work on controlled Field. You should use `initialValues` of Form instead.
Warning: [antd: Form.Item] `defaultValue` will not work on controlled Field. You should use `initialValues` of Form instead.
753 0
|
数据库
Field ‘id‘ doesn‘t have a default value
Field ‘id‘ doesn‘t have a default value
170 0
|
编解码 搜索推荐 算法
Data-Data Objects and Attribute Types| 学习笔记
快速学习 Data-Data Objects and Attribute Types。
Data-Data Objects and Attribute Types| 学习笔记