TS2339:“家"类型上不存在属性“道具" [英] TS2339: Property 'props' does not exist on type 'Home'

查看:37
本文介绍了TS2339:“家"类型上不存在属性“道具"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的与 tsx 反应的程序,我收到一个错误,我无法弄清楚原因

I have a very basic program of react with tsx, I am getting an error which I am not able to figure out why

import React from 'react';
// import {connect} from 'react-redux'

export class Home extends React.Component {    
    render(){
        console.log(this.props)
        return (
            <div>Working</div>
        )
    }
}


import * as React from 'react'
import * as ReactDOM from 'react-dom';
import {Home} from './Components/Home.component'
class App extends React.Component<any,any>{
render(){
    return(
        <Home value="abc" />
    )
  }
}
ReactDOM.render( <App />, window.document.getElementById("app"))

git clone 这个代码

git clone this for code

推荐答案

在拉下你的 repo 并检查它之后,我意识到你没有 react 类型 用于打字稿.

After pulling down your repo and inspecting it, I realised that you do not have react typings for typescript.

Typings 是管理和安装 TypeScript 定义的简单方法

Typings is the simple way to manage and install TypeScript definitions

添加这一行

"@types/react": "^16.0.25" // or another version you prefer

package.json 并再次运行 npm i 解决了这个问题.试试看,让我知道这是否能解决你的问题:)

to the package.json and running npm i one more time solved the issue. Try it out and let me know if this solves it on your side :)

PS:TypeScript 要求您描述对象和数据的形状.如果您查看我之前提供的其他答案,它几乎是的一个冗长而复杂的版本指定一个描述道具的类型,并需要将其传递给相关组件

PS: TypeScript requires you to describe the shape of your objects and your data. If you look at the other answer I provided earlier, it was pretty much a long and complicated version of You need to specify a type that describes your props and need to pass this to the component in question

这篇关于TS2339:“家"类型上不存在属性“道具"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆