【问题标题】:difference between with/without typeof in typescript打字稿中有/没有typeof的区别
【发布时间】: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;
}

【问题讨论】:

标签: reactjs typescript


【解决方案1】:

第一个没有意义,因为 typeof 只能应用于值,不能应用于类型。

【讨论】:

    【解决方案2】:

    TypeScript 添加了一个 typeof 运算符,您可以在类型上下文中使用它来引用变量或属性的类型

    learn more关于Typeof类型运算符

    【讨论】:

      猜你喜欢
      • 2015-05-25
      • 1970-01-01
      • 1970-01-01
      • 2016-07-08
      • 1970-01-01
      • 2016-09-15
      • 1970-01-01
      • 1970-01-01
      • 2016-08-13
      相关资源
      最近更新 更多