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。。。
563 0
|
3月前
ts中interface和type的区别
ts中interface和type的区别
140 21
|
7月前
|
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
360 0
|
6月前
|
JavaScript
error Component name “Login“ should always be multi-word vue/multi-word-component-names【已解决】
error Component name “Login“ should always be multi-word vue/multi-word-component-names【已解决】
371 1
【已解决】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
2570 0
【已解决】Error: Element type is invalid: expected a string (for built-in components) or a class/function
|
7月前
|
JavaScript
TS中 type和interface的区别
TS中 type和interface的区别
856 0
|
7月前
|
JavaScript 前端开发 索引
TS - interface和type的区别
TS - interface和type的区别
90 0
SpringCloudGateway中出现No primary or default constructor和web-application-type=reactive or remove
SpringCloudGateway中出现No primary or default constructor和web-application-type=reactive or remove
523 0
|
JavaScript 前端开发
成功解决Component template should contain exactly one root element
成功解决Component template should contain exactly one root element
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.
796 0