【发布时间】:2019-02-06 18:45:24
【问题描述】:
代码
import * as React from 'react';
import * as PropTypes from 'prop-types';
interface ILayoutProps {
dir?: 'horizontal' | 'vertical'
};
const Layout: React.FunctionComponent<ILayoutProps> = (props) => {
return (
<div>
{props.children}
</div>
);
};
Layout.defaultProps = {
dir: 'horizontal'
};
Layout.propTypes = {
dir: PropTypes.oneOf(['horizontal', 'vertical'])
};
export default Layout;
错误信息
TS2322: Type '{ dir: Requireable<string>; }' is not assignable to type 'ValidationMap<ILayoutProps>'.
Types of property 'dir' are incompatible.
Type 'Requireable<string>' is not assignable to type 'Validator<"horizontal" | "vertical" | undefined>'.
我应该如何定义 Layout.propTypes?
【问题讨论】:
-
至少在 typescript v3.5 之后这种情况已经停止发生。它仍在 3.3 中发生
标签: reactjs typescript react-proptypes