source: node_modules/react-immutable-proptypes/typings/index.d.ts

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 4.3 KB
Line 
1// Typescript typings for `react-immutable-proptypes`
2
3/** Copy of `React.PropTypes`'s `Validator` */
4interface Validator<T> {
5 (object: T, key: string, componentName: string, ...rest: any[]): Error | null;
6}
7
8/** Copy of `React.PropTypes`'s `Requireable<T>` */
9interface Requireable<T> extends Validator<T> {
10 isRequired: Validator<T>;
11}
12
13/** .
14 * Modification of `React.PropTypes`'s `ValidationMap<T>` type
15 *
16 * `type ValidationMap<T> = { [K in keyof T]?: Validator<T> };`
17 *
18 * original seemd too generic, since it allowed stings and numbers as args
19 */
20type ValidatorMap<T> = { [key: string]: Validator<T> };
21
22/** combination of */
23type ValidaterOrValidatorMap = Validator<any> | ValidatorMap<any>
24
25
26declare module 'react-immutable-proptypes' {
27 /**
28 * `ImmutablePropTypes.listOf` is based on `React.PropTypes.array` and
29 * is specific to `Immutable.List`
30 */
31 function listOf(typeChecker: ValidaterOrValidatorMap): Requireable<any>;
32
33 /**
34 * `ImmutablePropTypes.mapOf` allows you to control both map values and keys
35 * (in `Immutable.Map`, keys could be anything including another Immutable collections).
36 *
37 *
38 * It accepts two arguments - first one for values, second one for keys (_optional_).
39 *
40 * If you are interested in validation of keys only, just pass `React.PropTypes.any` as
41 * the first argument.
42 */
43 function mapOf(valuesTypeChecker: Requireable<any>, keysTypeChecker?: Requireable<any>): Requireable<any>;
44
45 /**
46 * `ImmutablePropTypes.orderedMapOf` is basically the same as `mapOf`,
47 * but it is specific to `Immutable.OrderedMap`.
48 */
49 function orderedMapOf(valuesTypeChecker: Requireable<any>, keysTypeChecker: Requireable<any>): Requireable<any>;
50
51 /**
52 * `ImmutablePropTypes.setOf` is basically the same as `listOf`,
53 * but it is specific to `Immutable.Set`.
54 */
55 function setOf(typeChecker: Requireable<any>): Requireable<any>;
56
57 /**
58 * `ImmutablePropTypes.orderedSetOf` is basically the same as `listOf`,
59 * but it is specific to `Immutable.OrderedSet`.
60 */
61 function orderedSetOf(typeChecker: Requireable<any>): Requireable<any>;
62
63 /**
64 * `ImmutablePropTypes.stackOf` is basically the same as `listOf`,
65 * but it is specific to `Immutable.Stack`.
66 */
67 function stackOf(typeChecker: Requireable<any>): Requireable<any>;
68
69 /**
70 * `ImmutablePropTypes.iterableOf` is the generic form of `listOf`/`mapOf`.
71 * It is useful when there is no need to validate anything other than Immutable.js
72 * compatible (ie. `Immutable.Iterable`).
73 *
74 * Continue to use `listOf` and/or `mapOf` when you know the type.
75 */
76 function iterableOf(typeChecker: Requireable<any>): Requireable<any>;
77
78 /**
79 * `ImmutablePropTypes.recordOf` is like contains,
80 * except it operates on `Record` properties.
81 */
82 function recordOf(recordKeys: ValidaterOrValidatorMap): Requireable<any>;
83
84 /**
85 * `ImmutablePropTypes.mapContains` is based on `React.PropTypes.shape` and will only work
86 * with `Immutable.Map`.
87 */
88 function shape(shapeTypes: ValidaterOrValidatorMap): Requireable<any>;
89
90 /**
91 * ImmutablePropTypes.contains (formerly `shape`) is based on `React.PropTypes.shape`
92 * and will try to work with any `Immutable.Iterable`.
93 *
94 * In my usage it is the most used validator, as I'm often trying to validate that a `map`
95 * has certain properties with certain values.
96 * @return {Requireable<any>}
97 */
98 function contains(shapeTypes: ValidaterOrValidatorMap): Requireable<any>;
99
100 /**
101 * `ImmutablePropTypes.mapContains` is based on `React.PropTypes.shape` and will only work
102 * with `Immutable.Map`.
103 */
104 function mapContains(shapeTypes: ValidaterOrValidatorMap): Requireable<any>;
105
106 /** checker for `Immutable.List.isList` */
107 const list: Requireable<any>;
108 /** checker for `Immutable.Map.isMap` */
109 const map: Requireable<any>;
110 /** checker for `Immutable.OrderedMap.isOrderedMap` */
111 const orderedMap: Requireable<any>;
112 /** checker for `Immutable.Set.isSet` */
113 const set: Requireable<any>;
114 /** checker for `Immutable.OrderedSet.isOrderedSet` */
115 const orderedSet: Requireable<any>;
116 /** checker for `Immutable.Stack.isStack` */
117 const stack: Requireable<any>;
118 /** checker for `Immutable.Seq.isSeq` */
119 const seq: Requireable<any>;
120 /** checker for `instanceof Record` */
121 const record: Requireable<any>;
122 /** checker for `Immutable.Iterable.isIterable` */
123 const iterable: Requireable<any>;
124}
Note: See TracBrowser for help on using the repository browser.