-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.d.ts
38 lines (32 loc) · 1.04 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React from 'react';
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
type Partial<T> = { [P in keyof T]?: T[P] };
export type InjectedQueryParams<QueryT = {}> = {
queryParams: QueryT;
setQueryParams: (queryParams: Partial<QueryT>) => void;
};
type RequiredDefault<T, P> = {
default: T | ((val: T, props: P) => T);
validate: (val: T, props: P) => boolean;
};
type OptionalDefault<T, P> = {
default?: T | ((val: T | undefined, props: P) => T);
validate: (val: T | undefined, props: P) => boolean;
};
export default function withQueryParams<QueryT = {}, OuterProps = {}>({
keys,
stripUnknownKeys,
queryStringOptions,
}: {
keys: {
[K in keyof QueryT]: undefined extends QueryT[K]
? OptionalDefault<QueryT[K], OuterProps>
: RequiredDefault<QueryT[K], OuterProps>;
};
stripUnknownKeys?: boolean;
queryStringOptions?: {
arrayFormat?: 'none' | 'bracket' | 'index';
};
}): <P>(
Wrapped: React.ComponentType<P & InjectedQueryParams<QueryT>>
) => React.FunctionComponent<Omit<P, keyof InjectedQueryParams<QueryT>>>;