流不显示错误或键入提示。在这个从重组文档中精简的示例中,您可以看到它的实际效果。
https://github.com/acdlite/recompose/tree/master/types
以下示例定义了一种标题类型,该标题必须为字符串。直接使用该组件时会显示错误。使用增强型组件时,不会显示错误。
/* @flow */
import React from 'react'
import { compose } from 'recompose'
import type { HOC } from 'recompose'
type ItemProps = {
title: string,
}
const Item = ({ title }: ItemProps) => (
<div />
)
const enhanceItem: HOC<*, ItemProps> = compose()
const EnhancedItem = enhanceItem(Item)
const DoesNotWork = () => (
<EnhancedItem title={() => {}} />
)
const Works = () => (
<Item title={() => {}} />
)