【发布时间】:2023-01-11 08:58:26
【问题描述】:
接口前有/没有typeof有什么区别?
它会改变行为吗?我找不到这方面的文档。
interface Props {
children: React.ReactNode;
}
type Item = React.FC<Props>;
type Component = React.FC & {
Item: typeof Item;
}
interface Props {
children: React.ReactNode;
}
type Item = React.FC<Props>;
type Component = React.FC & {
Item: Item;
}
【问题讨论】:
-
typeof用于提取值的类型,或者作为一种特殊情况,用于提取类的构造函数类型。在这个例子中,你的第一个 sn-p 应该有一个错误:Item only refers to a type, but is being used as a value here,表明在那个地方使用typeof是无效的。 -
请记住
typeof类型运算符是打字稿功能,与built-in javascripttypeofvalue operator, which can be read about here.不同
标签: reactjs typescript