前提・実現したいこと
TypeScriptを使ってReactのスクリプトを書いています。
IDEで型のエラーが出るのですが、見よう見まねで書いているため、一箇所(Menu.propTypesの箇所)だけどうしてもエラーの解決方法がわかりません。
型指定の問題だとは思うのですが…。
どのように指定すれば解決できるのか教えていただけると幸いです。
発生している問題・エラーメッセージ
TS2329: Property 'propTypes' does not exist on type 'typeof Menu'.
該当のソースコード
TypeScript
1import React, {Component} from "react"; 2import { fetchPosts } from "../../actions"; 3import {connect} from "react-redux"; 4import PropTypes from 'prop-types'; 5 6type Props = any; 7 8class Menu extends Component<Props, {}> { 9 componentDidMount(): void { 10 this.props.fetchPosts(); 11 } 12 13 renderPosts() { 14 return this.props.posts.map((post: any) => ( 15 <li className="menu-list__item" key={post.id}> 16 <h4>{post.title.rendered}</h4> 17 <div 18 className="menu-list__content" 19 dangerouslySetInnerHTML={{ __html: post.content.rendered }} 20 /> 21 </li> 22 )) 23 } 24 25 render() { 26 return ( 27 <div className="menu"> 28 <h2>Espresso Collection</h2> 29 <ul className="menu_list"> 30 { this.renderPosts() } 31 </ul> 32 </div> 33 ) 34 } 35} 36 37function maoStateToProps (state: any) { 38 return { posts: state.posts.data } 39} 40 41Menu.propTypes = { 42 fetchPosts: PropTypes.func.isRequired 43}; 44 45export default connect(maoStateToProps, { fetchPosts })(Menu);
試したこと
class Menuとなっているところをclass Menu: anyなどとしてみましたが、
書式として正しくないようなので駄目でした…。
補足情報(FW/ツールのバージョンなど)
▼tsconfig
json
1{ 2 "compilerOptions": { 3 "sourceMap": true, 4 "target": "es5", 5 "module": "commonjs", 6 "strict": true, 7 "jsx": "react", 8 "lib": ["es5", "es6", "dom"], 9 "moduleResolution": "node", 10 "noImplicitAny": true, 11 "noImplicitThis": true, 12 "noUnusedLocals": true, 13 "noUnusedParameters": true, 14 "strictNullChecks": true, 15 "noImplicitReturns": true, 16 "removeComments": true, 17 "allowSyntheticDefaultImports": true, 18 "esModuleInterop": true 19 }, 20 "include": [ 21 "./src/**/*" 22 ], 23 "exclude": [ 24 "node_modules" 25 ] 26}
▼tslint
json
1{ 2 "rulesDirectory": [ 3 "tslint-plugin-prettier" 4 ], 5 "extends": [ 6 "tslint-config-standard", 7 "tslint-config-prettier" 8 ], 9 "rules": { 10 "indent": [true, "tabs", 4], 11 "prettier": [ 12 true, 13 { 14 "useTabs": true, 15 "tabWidth": 4, 16 "singleQuote": true, 17 "semi": true 18 } 19 ] 20 } 21}
お手数おかけしますがよろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。