本文整理汇总了TypeScript中prop-types.checkPropTypes函数的典型用法代码示例。如果您正苦于以下问题:TypeScript checkPropTypes函数的具体用法?TypeScript checkPropTypes怎么用?TypeScript checkPropTypes使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了checkPropTypes函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('can check propTypes for fragments', () => {
const propTypes = {
foo: propType(fragment),
};
checkPropTypes(propTypes, filteredData, 'prop', 'MyComponent');
expect(global.console.error).not.toHaveBeenCalled();
checkPropTypes(propTypes, { foo: {} }, 'prop', 'MyComponent');
expect(global.console.error.mock.calls[0]).toMatchSnapshot();
});
示例2:
type ExtractPropsMatch3 = ExtractedProps extends Props ? true : false;
// $ExpectType true
type ExtractPropsMatch4 = Props extends ExtractedPropsWithoutAnnotation ? true : false;
// $ExpectType true
type ExtractFromOuterPropsMatch = ExtractedPropsFromOuterProps extends ExtractedPropsFromOuterPropsWithoutAnnotation ? true : false;
// $ExpectType true
type ExtractFromOuterPropsMatch2 = ExtractedPropsFromOuterPropsWithoutAnnotation extends ExtractedPropsFromOuterProps ? true : false;
// $ExpectType true
type ExtractFromOuterPropsMatch3 = ExtractedPropsFromOuterProps extends Props ? true : false;
// $ExpectType true
type ExtractFromOuterPropsMatch4 = Props extends ExtractedPropsFromOuterPropsWithoutAnnotation ? true : false;
// $ExpectType false
type ExtractPropsMismatch = ExtractedPartialProps extends Props ? true : false;
PropTypes.checkPropTypes({ xs: PropTypes.array }, { xs: [] }, 'location', 'componentName');
// This would be the type that JSX sees
type Defaultize<T, D> =
& Pick<T, Exclude<keyof T, keyof D>>
& Partial<Pick<T, Extract<keyof T, keyof D>>>
& Partial<Pick<D, Exclude<keyof D, keyof T>>>;
// This would be the type inside the component
type Undefaultize<T, D> =
& Pick<T, Exclude<keyof T, keyof D>>
& { [K in Extract<keyof T, keyof D>]-?: Exclude<T[K], undefined>; }
& Required<Pick<D, Exclude<keyof D, keyof T>>>;
const componentPropTypes = {
fi: PropTypes.func.isRequired,