[英]How to fix (Missing: any) in create-react-app with TS
I call BookTracker component in my root App.tsx, with book={MY_MOCK}, 我在我的根App.tsx中调用BookTracker组件,book = {MY_MOCK},
type BookParamsTypes = {
title: string;
pubDate: number;
//... rest
};
import { BookParamsTypes } from "./types/BookParamsTypes";
type BookTrackerProps = {
book: BookParamsTypes[];
};
const BookTracker = ({ book }: BookTrackerProps) => (
//...
<BookDetailed book={book}/>
//...
);
for the BookDetailed above i have an error message "JSX element type '{ book: BookParamsTypes[]; (Missing): any; }' is not a constructor function for JSX elements. Type '{ book: BookParamsTypes[]; (Missing): any; }' is missing the following properties from type 'Element': type, props, key - ts(2605)" how come this be? 对于上面的BookDetailed我有一个错误消息“JSX元素类型'{book:BookParamsTypes [];(缺失):any;}'不是JSX元素的构造函数。输入'{book:BookParamsTypes [];(Missing) :any;}'缺少类型'Element'的以下属性:type,props,key-ts(2605)“怎么会这样? no clues
没有线索
And then i cannot properly map inside BookDetailed 然后我无法正确映射BookDetailed内部
{book.map((item, i: number) => (
// ..
<BookTitle>{item.title}</BookTitle>
// ... rest
))}
Linter doesnt understand book.map at all and also says item implicitly has any type ... Linter根本不理解book.map并且还说item隐式有任何类型 ......
For other reference, here is my tsconfig: 对于其他参考,这是我的tsconfig:
{ "compilerOptions": { "target": "es5", "lib": [ "dom", "dom.iterable", "esnext" ], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "strict": true, "forceConsistentCasingInFileNames": true, "module": "esnext", "moduleResolution": "node", "resolveJsonModule": true, "noEmit": true, "jsx": "preserve", "noUnusedLocals": true, "noUnusedParameters": true, "removeComments": false, "preserveConstEnums": true, "types": [], "isolatedModules": true }, "include": [ "src/*" ], "exclude": [ "node_modules", "**/*.spec.ts", "**/*.spec.ts", "src/sw-*.js", "src/idb.js" ] }
and package.json 和package.json
"dependencies": { "@types/jest": "24.0.11", "@types/node": "11.13.6", "@types/react": "16.8.14", "@types/react-dom": "16.8.4", "@types/styled-components": "^4.1.14", "react": "^16.8.6", "react-dom": "^16.8.6", "react-scripts": "2.1.8", "styled-components": "^4.2.0", "typescript": "3.4.4" } "devDependencies": { "babel-plugin-styled-components": "^1.10.0", "stylelint": "^10.0.1", "tslint": "^5.16.0", "tslint-config-airbnb": "^5.11.1", "tslint-config-prettier": "^1.18.0", "tslint-react": "^4.0.0" }
Maybe i have some sort of tslint / config conflicts? 也许我有某种tslint /配置冲突? Can please some one help me figure it out?
可以请一些人帮我搞清楚吗?
确保正确定义了BookDetailed
组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.