首页 > 解决方案 > 在组件中设置类型?

问题描述

有人能解释一下这个语法在做什么吗?我没见过太多

type ScrollProps = {
  location: Object,
  elementID?: string
};

class ScrollMemory extends Component<ScrollProps> {
  detectPop: () => void;
  url: Map<string, number>;

原始来源

https://github.com/ipatate/react-router-scroll-memory/blob/master/src/ScrollMemory.js

标签: reactjs

解决方案


类型检查!这是为您的组件设置类型。这反过来将 IntelliSense/Typechecking 添加到您的代码中(如果您的 IDE 支持它)。

您链接的示例使用流。如果您想了解更多信息,请查看https://flow.org/


推荐阅读