Home > Back-end >  difference between with/without typeof in typescript
difference between with/without typeof in typescript

Time:01-11

What is the difference between with/without typeof before interface?

Does it change the behavior? I couldn't find the doc for this.

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;
}

CodePudding user response:

The first one doesn't make sense because typeof can only be applied to values, not to types.

CodePudding user response:

TypeScript adds a typeof operator you can use in a type context to refer to the type of a variable or property

learn more about Typeof Type Operator

  • Related