import * as React from 'react'; import * as PropTypes from 'prop-types'; import * as AirbnbPropTypes from 'airbnb-prop-types'; class ClassComp extends React.Component { render() { return null; } } function FuncComp() { return null; } // $ExpectType Requireable AirbnbPropTypes.and([PropTypes.number]); // $ExpectType Requireable AirbnbPropTypes.and([PropTypes.number, AirbnbPropTypes.nonNegativeInteger]); // $ExpectType Validator AirbnbPropTypes.and([PropTypes.number, AirbnbPropTypes.integer()], 'foo').isRequired; // $ExpectType Requireable AirbnbPropTypes.between({ lt: 1 }); // $ExpectType Requireable AirbnbPropTypes.between({ lte: 2 }); // $ExpectType Requireable AirbnbPropTypes.between({ gt: 3 }); // $ExpectType Requireable AirbnbPropTypes.between({ gte: 4 }); // $ExpectType Requireable AirbnbPropTypes.between({ lt: 1, gt: 0 }); // $ExpectType Requireable AirbnbPropTypes.booleanSome('foo', 'bar', 'baz'); // $ExpectType Requireable AirbnbPropTypes.childrenHavePropXorChildren('foo'); // $ExpectType Requireable AirbnbPropTypes.childrenOf(PropTypes.string); // $ExpectType Requireable AirbnbPropTypes.childrenOfType(ClassComp); // $ExpectType Requireable AirbnbPropTypes.childrenOfType(FuncComp); // $ExpectType Requireable AirbnbPropTypes.childrenOfType('div'); // $ExpectType Requireable AirbnbPropTypes.childrenOfType(ClassComp, FuncComp, 'div'); // $ExpectType Requireable AirbnbPropTypes.childrenSequenceOf({ validator: PropTypes.number }); // $ExpectType Requireable AirbnbPropTypes.childrenSequenceOf({ validator: PropTypes.string, max: 100 }); // $ExpectType Requireable AirbnbPropTypes.childrenSequenceOf({ validator: PropTypes.bool, min: 0 }); // $ExpectType Requireable AirbnbPropTypes.componentWithName('Foo'); // $ExpectType Requireable AirbnbPropTypes.componentWithName(/Foo/); // $ExpectType Requireable AirbnbPropTypes.componentWithName('Foo', { stripHOCs: ['connect'] }); // $ExpectType Requireable AirbnbPropTypes.disallowedIf(PropTypes.number, 'foo', PropTypes.string); // $ExpectType Requireable AirbnbPropTypes.elementType(ClassComp); // $ExpectType Requireable AirbnbPropTypes.elementType(FuncComp); // $ExpectType Requireable AirbnbPropTypes.elementType('div'); // $ExpectType Requireable AirbnbPropTypes.elementType('*'); // $ExpectError AirbnbPropTypes.elementType(ClassComp, FuncComp, 'div'); // $ExpectType Requireable AirbnbPropTypes.explicitNull(); // $ExpectType Validator AirbnbPropTypes.explicitNull().isRequired; interface ForbidShape { foo: string; bar: number; baz?: boolean | null; } // $ExpectType ValidationMap<{ foo: string | null | undefined; bar: number; baz: boolean | null | undefined; }> AirbnbPropTypes.forbidExtraProps({ foo: PropTypes.string, bar: PropTypes.number.isRequired, baz: PropTypes.bool, }); // $ExpectType ValidationMap AirbnbPropTypes.forbidExtraProps({ foo: PropTypes.string.isRequired, bar: PropTypes.number.isRequired, baz: PropTypes.bool, }); // $ExpectType Requireable AirbnbPropTypes.integer(); const top = ((x?: T): T => x!)(); type Top = typeof top; declare function validateRequireableTop(x: React.Requireable): void; validateRequireableTop(AirbnbPropTypes.keysOf(PropTypes.number)); validateRequireableTop(AirbnbPropTypes.keysOf(PropTypes.number, 'foo')); validateRequireableTop(AirbnbPropTypes.keysOf(PropTypes.oneOf(['foo', 'bar']))); // $ExpectType Requireable AirbnbPropTypes.mutuallyExclusiveProps(PropTypes.number); // $ExpectType Requireable AirbnbPropTypes.mutuallyExclusiveProps(PropTypes.number, 'foo'); // $ExpectType Requireable AirbnbPropTypes.mutuallyExclusiveProps(PropTypes.string, 'foo', 'bar'); // $ExpectType Requireable AirbnbPropTypes.mutuallyExclusiveTrueProps('foo'); // $ExpectType Requireable AirbnbPropTypes.mutuallyExclusiveTrueProps('foo', 'bar'); // $ExpectType Requireable AirbnbPropTypes.nChildren(1, PropTypes.number); // $ExpectType Requireable AirbnbPropTypes.nChildren(1, AirbnbPropTypes.childrenOfType('span')); // $ExpectType Requireable AirbnbPropTypes.nonNegativeInteger; // $ExpectType Requireable AirbnbPropTypes.nonNegativeNumber(); // $ExpectType Requireable AirbnbPropTypes.numericString(); // $ExpectType Requireable const props: PropTypes.Requireable = AirbnbPropTypes.object(); // $ExpectType Requireable<{ foo: string; }> AirbnbPropTypes.object<{ foo: string }>(); AirbnbPropTypes.or([PropTypes.bool.isRequired, AirbnbPropTypes.explicitNull().isRequired]); AirbnbPropTypes.or([PropTypes.bool, PropTypes.number, PropTypes.arrayOf(PropTypes.string)]); AirbnbPropTypes.or([PropTypes.number, PropTypes.string, PropTypes.bool], 'foo'); // $ExpectType Requireable AirbnbPropTypes.range(0, 10); // $ExpectType Requireable<5> AirbnbPropTypes.range<5>(0, 10); // $ExpectType Requireable> AirbnbPropTypes.ref(); // $ExpectType Requireable AirbnbPropTypes.requiredBy('foo', PropTypes.string); // $ExpectType Validator AirbnbPropTypes.requiredBy('bar', PropTypes.number, 42).isRequired; validateRequireableTop(AirbnbPropTypes.restrictedProp()); validateRequireableTop(AirbnbPropTypes.restrictedProp(() => 'Error')); validateRequireableTop(AirbnbPropTypes.restrictedProp(() => new Error('Error'))); validateRequireableTop(AirbnbPropTypes.sequenceOf({ validator: PropTypes.number })); validateRequireableTop(AirbnbPropTypes.sequenceOf({ validator: PropTypes.number }, { validator: PropTypes.string })); validateRequireableTop(AirbnbPropTypes.sequenceOf( { validator: PropTypes.number, min: 0, max: 10 }, { validator: PropTypes.string }, { validator: PropTypes.bool }, )); interface ShapeShape { foo: string; bar?: number | null; } // $ExpectType Requireable<{ foo: string | null | undefined; }> AirbnbPropTypes.shape({ foo: PropTypes.string, }); // $ExpectType Requireable<{ foo: string | null | undefined; bar: number | null | undefined; }> AirbnbPropTypes.shape({ foo: PropTypes.string, bar: PropTypes.number, }); // $ExpectType Requireable AirbnbPropTypes.shape({ foo: PropTypes.string.isRequired, bar: PropTypes.number, }); // $ExpectType Requireable AirbnbPropTypes.stringStartsWith('foo'); // $ExpectType Requireable AirbnbPropTypes.uniqueArray(); // $ExpectType Requireable AirbnbPropTypes.uniqueArray(); // $ExpectType Requireable<{ [key: string]: number | null | undefined; }> AirbnbPropTypes.valuesOf(PropTypes.number);