reactjs - Typescript - React.FC 是任何而不是检查道具
问题描述
我创建了一个reactjs
应用程序使用npx create-react-app myapp --template typescript
我创建的组件
import React from 'react';
interface IPerson {
name: string;
age: number;
}
const Person:React.FC<IPerson> = (props:IPerson) => {
const {name, age} = props;
return <div>{name} {age}</div>;
}
如果我没有通过所需的道具,那么打字稿也不会抛出任何错误。即使我运行应用程序,我也没有收到任何警告或错误。
<Person name='xyz' />
上面的行应该抛出错误。但它工作正常。
我试图找到原因,但没有找到可以解决此问题的方法。我发现的只是当我将鼠标悬停在一个React.FC
它显示的 typeany
而不是 type 时IPerson
。
如果有人可以对此有所了解,将不胜感激。
解决方案
当我npm install
再次运行时,我注意到终端中存在以下错误:
gyp: No Xcode or CLT version detected!
gyp ERR! configure error
我做了以下步骤来解决这个问题:
xcode-select --print-path // this will give path of xcode-select install. use it to remove it;
sudo rm -r -f /Library/Developer/CommandLineTools
xcode-select --install // install it again
在我运行npm install
VSCode 的上述步骤之后,如果缺少所需的道具,则开始抛出错误。
推荐阅读
- angular - 在不同的组件Angular 6中获取价值
- vpn - shadowsocks 打不开 https://scholar.google.com
- r - 使用不同的质心数值运行 K-Means 的多次迭代
- javascript - Bootstrap 无法与 VueJS 中的数组道具一起正常工作
- java - 如何从java中的分隔字符串中提取整数
- python - 整数列表上的 CountVectorizer
- javascript - 如何在 Meteor 的后端读取文件?
- java - 线程“主”org.lwjgl.opengl.OpenGLException 中的异常:操作无效 (1282)
- ios - 推送新的 UIViewController 时 UISearchController 消失
- sitecore - SitecoreJSS 9.1 发布日期和 SitecoreJSS 9 限制