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。。。
557 0
|
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
340 0
【已解决】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
2568 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‘
91 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]
154 0
|
7月前
|
JavaScript API
Property ‘proxy‘ does not exist on type ‘ComponentInternalInstance | null‘.ts
Property ‘proxy‘ does not exist on type ‘ComponentInternalInstance | null‘.ts
|
Scala
TYPE
TYPE
146 0
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.
780 0
|
数据库
Field ‘id‘ doesn‘t have a default value
Field ‘id‘ doesn‘t have a default value
176 0
Extraneous children found when component already has explicitly named default slot. These children
Extraneous children found when component already has explicitly named default slot. These children
1291 5