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;

解决方案

指定为显示数据类型



后言

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


目录
相关文章
|
4月前
|
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
75 0
|
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。。。
470 0
|
7月前
Property ‘Authorization‘ does not exist on type ‘HeadersDefaults‘
Property ‘Authorization‘ does not exist on type ‘HeadersDefaults‘
38 0
|
10月前
Unknown custom element: <add-employee> - did you register the component correctly? For red cursive c
原因: 1.组件名没写对(导入和注册不对应) 2.components少写了个s 3.组件命名最好是驼峰命名 4.导入时语法错误 5.代码中有两个components,后一个的值把前一个覆盖了 6.组件直接循环套用了
|
5月前
|
JavaScript API
Property ‘proxy‘ does not exist on type ‘ComponentInternalInstance | null‘.ts
Property ‘proxy‘ does not exist on type ‘ComponentInternalInstance | null‘.ts
|
9月前
|
JavaScript 前端开发
成功解决Component template should contain exactly one root element
成功解决Component template should contain exactly one root element
|
11月前
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.
321 0
|
11月前
|
数据库
Field ‘id‘ doesn‘t have a default value
Field ‘id‘ doesn‘t have a default value
121 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
1052 5
how is opportunity detail page display first item by default
how is opportunity detail page display first item by default
72 0
how is opportunity detail page display first item by default