diff --git a/types/react-immutable-proptypes/index.d.ts b/types/react-immutable-proptypes/index.d.ts new file mode 100644 index 0000000000..51130774ac --- /dev/null +++ b/types/react-immutable-proptypes/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for react-immutable-proptypes 2.1 +// Project: https://github.com/HurricaneJames/react-immutable-proptypes +// Definitions by: Joris van der Wel +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import { Validator, Requireable, ValidationMap } from 'prop-types'; +import * as Immutable from 'immutable'; + +export function listOf(type: Validator): Requireable>; +export function mapOf(valueType: Validator, keyType?: Validator): Requireable>; +export function orderedMapOf(valueType: Validator, keyType?: Validator): Requireable>; +export function setOf(type: Validator): Requireable>; +export function orderedSetOf(type: Validator): Requireable>; +export function stackOf(type: Validator): Requireable>; +export function iterableOf(type: Validator): Requireable>; +// todo: recordOf can be made more useful when immutable v4 releases, because it has much better typescript +// support (for example by setting the return type to RecordOf>) +export function recordOf(type: ValidationMap): Requireable>; +export function shape(type: ValidationMap): Requireable>; +export function contains(type: ValidationMap): Requireable>; +export function mapContains(type: ValidationMap): Requireable>; +export const list: Requireable>; +export const map: Requireable>; +export const orderedMap: Requireable>; +export const set: Requireable>; +export const orderedSet: Requireable>; +export const stack: Requireable>; +export const seq: Requireable>; +export const record: Requireable>; +export const iterable: Requireable>; diff --git a/types/react-immutable-proptypes/package.json b/types/react-immutable-proptypes/package.json new file mode 100644 index 0000000000..12231bb461 --- /dev/null +++ b/types/react-immutable-proptypes/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "immutable": "^3.8.2" + } +} diff --git a/types/react-immutable-proptypes/react-immutable-proptypes-tests.ts b/types/react-immutable-proptypes/react-immutable-proptypes-tests.ts new file mode 100644 index 0000000000..e6a55aebca --- /dev/null +++ b/types/react-immutable-proptypes/react-immutable-proptypes-tests.ts @@ -0,0 +1,86 @@ +import * as PropTypes from 'prop-types'; +import * as Immutable from 'immutable'; +import * as ImmutablePropTypes from 'react-immutable-proptypes'; + +interface Props { + list: Immutable.List; + map: Immutable.Map; + orderedMap: Immutable.OrderedMap; + set: Immutable.Set; + orderedSet: Immutable.OrderedSet; + stack: Immutable.Stack; + seq: Immutable.Seq; + record: Immutable.Map; + iterable: Immutable.Iterable; + listOf: Immutable.List; + mapOf: Immutable.Map; + mapOfNoKey: Immutable.Map; + orderedMapOf: Immutable.OrderedMap; + orderedMapOfNoKey: Immutable.OrderedMap; + setOf: Immutable.Set; + orderedSetOf: Immutable.OrderedSet; + stackOf: Immutable.Stack; + iterableOf: Immutable.Iterable; + recordOf: Immutable.Map; + shape: Immutable.Iterable; + contains: Immutable.Iterable; + mapContains: Immutable.Map; +} + +const propTypes: PropTypes.ValidationMap = { + list: ImmutablePropTypes.list.isRequired, + map: ImmutablePropTypes.map.isRequired, + orderedMap: ImmutablePropTypes.orderedMap.isRequired, + set: ImmutablePropTypes.set.isRequired, + orderedSet: ImmutablePropTypes.orderedSet.isRequired, + stack: ImmutablePropTypes.stack.isRequired, + seq: ImmutablePropTypes.seq.isRequired, + record: ImmutablePropTypes.record.isRequired, + iterable: ImmutablePropTypes.iterable.isRequired, + listOf: ImmutablePropTypes.listOf( + PropTypes.string.isRequired + ).isRequired, + mapOf: ImmutablePropTypes.mapOf( + PropTypes.number.isRequired, + PropTypes.string.isRequired + ).isRequired, + mapOfNoKey: ImmutablePropTypes.mapOf( + PropTypes.number.isRequired + ).isRequired, + orderedMapOf: ImmutablePropTypes.orderedMapOf( + PropTypes.number.isRequired, + PropTypes.string.isRequired + ).isRequired, + orderedMapOfNoKey: ImmutablePropTypes.orderedMapOf( + PropTypes.number.isRequired + ).isRequired, + setOf: ImmutablePropTypes.setOf( + PropTypes.string.isRequired + ).isRequired, + orderedSetOf: ImmutablePropTypes.orderedSetOf( + PropTypes.string.isRequired + ).isRequired, + stackOf: ImmutablePropTypes.stackOf( + PropTypes.string.isRequired + ).isRequired, + iterableOf: ImmutablePropTypes.iterableOf( + PropTypes.string.isRequired + ).isRequired, + recordOf: ImmutablePropTypes.recordOf({ + foo: PropTypes.string.isRequired, + }).isRequired, + shape: ImmutablePropTypes.shape({ + foo: PropTypes.string.isRequired, + }).isRequired, + contains: ImmutablePropTypes.contains({ + foo: PropTypes.string.isRequired, + }).isRequired, + mapContains: ImmutablePropTypes.mapContains({ + foo: PropTypes.string.isRequired, + }).isRequired, +}; + +type ExtractedProps = PropTypes.InferProps; + +// $ExpectType true +type ExtractPropsMatch = ExtractedProps extends Props ? true : false; diff --git a/types/react-immutable-proptypes/tsconfig.json b/types/react-immutable-proptypes/tsconfig.json new file mode 100644 index 0000000000..785c86edeb --- /dev/null +++ b/types/react-immutable-proptypes/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-immutable-proptypes-tests.ts" + ] +} diff --git a/types/react-immutable-proptypes/tslint.json b/types/react-immutable-proptypes/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-immutable-proptypes/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }