[英]Typescript - React.FC is any and not checking props
I've created a reactjs
applicaiton using npx create-react-app myapp --template typescript
我使用
reactjs
npx create-react-app myapp --template typescript
创建了一个reactjs
应用程序
My created component我创建的组件
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>;
}
If I don't pass the required props even then typescript is not throwing any error.如果我没有通过所需的道具,即使打字稿也不会抛出任何错误。 Even if I run the application I am not getting any kind of warning or error.
即使我运行该应用程序,我也没有收到任何警告或错误。
<Person name='xyz' />
Above line supposed to throw error.上面的行应该抛出错误。 But it is working fine.
但它工作正常。
I tried to find the cause but haven't found something which can fix this.我试图找到原因,但还没有找到可以解决这个问题的东西。 All I found is when I hover one
React.FC
it shown of type any
instead of type IPerson
.我发现的是,当我将一个
React.FC
悬停时,它显示的类型为any
而不是类型IPerson
。
It would be really appreciated if someone can put some light on it.如果有人能对此有所了解,我们将不胜感激。
When I ran npm install
again then I noticed that following error was there in terminal:当我再次运行
npm install
时,我注意到终端中有以下错误:
gyp: No Xcode or CLT version detected!
gyp ERR! configure error
I did following steps to fix this:我做了以下步骤来解决这个问题:
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
After the above steps when I ran npm install
VSCode started throwing error if required props are missing.在我运行
npm install
VSCode 执行上述步骤后,如果缺少所需的道具,则开始抛出错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.