我在哪里从库中获取变量的打字稿类型
我一直在研究一个反应型项目,在该项目中,我正在使用很多外部库,并且经常发现自己使用为这些库中使用任何类型。请查看下面的代码进行演示,
这是针对上述代码的 fontawesome库
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
faSquare,
} from '@fortawesome/free-regular-svg-icons';
interface IProps {
title: string;
icon: any;
onClick?: () => void;
sx?: { [index: string]: string };
}
const icons ={
title :_,
icon : faSquare
}
, Icon的类型是什么类型。其价值为 fasquare 。当我徘徊时,类型为 icondefinition 。但是,我不确定要在哪里导入它,或者是这样做的方法。
I have been working on a react-typescript project in which I am using a lot of external libraries and I frequently find myself using any type for those libraries. Please look at the code below for the demonstration
This is for the Fontawesome library
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
faSquare,
} from '@fortawesome/free-regular-svg-icons';
interface IProps {
title: string;
icon: any;
onClick?: () => void;
sx?: { [index: string]: string };
}
const icons ={
title :_,
icon : faSquare
}
For the above code, what would be the type of icon. The value of which is faSquare. When I hovered over it the type is IconDefinition. But, I am not sure where to import it or if that is the way to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@fortawesome
软件包嵌入了自己的类型,因此自动推断出icons.icon的类型
。在VSCODE中,您可以右键单击并“转到类型定义”以检查类型。
在您的情况下,
fasquare
的类型是icondefinition
您只需将其从
@fortawesome/fortawesome/free-free-regular-Svg-icons'
The
@fortawesome
packages embed their own types, thus the type oficons.icon
is inferred automatically.In VSCode, you can right-click and "Go to type definition" to check type.
In your case, the type of
faSquare
isIconDefinition
You can just add it to your import from
@fortawesome/free-regular-svg-icons'