Skip to content

Commit

Permalink
fix(type): Reduce the number of type parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
shinout committed Apr 6, 2019
1 parent 7608816 commit 273926e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 216 deletions.
170 changes: 13 additions & 157 deletions modules/format/src/common/bound-document-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,39 +102,6 @@ export type BoundDocumentPathOfDepth8<
object: T;
};

export type BoundDocumentPathOfDepth9<
T extends Object,
K1 extends keyof T,
K2 extends keyof T[K1],
K3 extends keyof T[K1][K2],
K4 extends keyof T[K1][K2][K3],
K5 extends keyof T[K1][K2][K3][K4],
K6 extends keyof T[K1][K2][K3][K4][K5],
K7 extends keyof T[K1][K2][K3][K4][K5][K6],
K8 extends keyof T[K1][K2][K3][K4][K5][K6][K7],
K9 extends keyof T[K1][K2][K3][K4][K5][K6][K7][K8]
> = string & {
keys: [K1, K2, K3, K4, K5, K6, K7, K8, K9];
object: T;
};

export type BoundDocumentPathOfDepth10<
T extends Object,
K1 extends keyof T,
K2 extends keyof T[K1],
K3 extends keyof T[K1][K2],
K4 extends keyof T[K1][K2][K3],
K5 extends keyof T[K1][K2][K3][K4],
K6 extends keyof T[K1][K2][K3][K4][K5],
K7 extends keyof T[K1][K2][K3][K4][K5][K6],
K8 extends keyof T[K1][K2][K3][K4][K5][K6][K7],
K9 extends keyof T[K1][K2][K3][K4][K5][K6][K7][K8],
K10 extends keyof T[K1][K2][K3][K4][K5][K6][K7][K8][K9]
> = string & {
keys: [K1, K2, K3, K4, K5, K6, K7, K8, K9, K10];
object: T;
};

export type BoundDocumentPath<
T,
K1,
Expand All @@ -144,22 +111,8 @@ export type BoundDocumentPath<
K5,
K6,
K7,
K8,
K9,
K10
> = RawBoundDocumentPath<
DeepRequired<T>,
K1,
K2,
K3,
K4,
K5,
K6,
K7,
K8,
K9,
K10
>;
K8
> = RawBoundDocumentPath<DeepRequired<T>, K1, K2, K3, K4, K5, K6, K7, K8>;

type RawBoundDocumentPath<
T,
Expand All @@ -170,9 +123,7 @@ type RawBoundDocumentPath<
K5,
K6,
K7,
K8,
K9,
K10
K8
> = K1 extends keyof T
? K2 extends keyof T[K1]
? K3 extends keyof T[K1][K2]
Expand All @@ -181,34 +132,7 @@ type RawBoundDocumentPath<
? K6 extends keyof T[K1][K2][K3][K4][K5]
? K7 extends keyof T[K1][K2][K3][K4][K5][K6]
? K8 extends keyof T[K1][K2][K3][K4][K5][K6][K7]
? K9 extends keyof T[K1][K2][K3][K4][K5][K6][K7][K8]
? K10 extends keyof T[K1][K2][K3][K4][K5][K6][K7][K8][K9]
? BoundDocumentPathOfDepth10<
T,
K1,
K2,
K3,
K4,
K5,
K6,
K7,
K8,
K9,
K10
>
: BoundDocumentPathOfDepth9<
T,
K1,
K2,
K3,
K4,
K5,
K6,
K7,
K8,
K9
>
: BoundDocumentPathOfDepth8<T, K1, K2, K3, K4, K5, K6, K7, K8>
? BoundDocumentPathOfDepth8<T, K1, K2, K3, K4, K5, K6, K7, K8>
: BoundDocumentPathOfDepth7<T, K1, K2, K3, K4, K5, K6, K7>
: BoundDocumentPathOfDepth6<T, K1, K2, K3, K4, K5, K6>
: BoundDocumentPathOfDepth5<T, K1, K2, K3, K4, K5>
Expand Down Expand Up @@ -308,70 +232,24 @@ interface RawBoundDocumentPathCreator<T> {
k7: K7,
k8: K8
): BoundDocumentPathOfDepth8<T, K1, K2, K3, K4, K5, K6, K7, K8>;
<
K1 extends keyof T,
K2 extends keyof T[K1],
K3 extends keyof T[K1][K2],
K4 extends keyof T[K1][K2][K3],
K5 extends keyof T[K1][K2][K3][K4],
K6 extends keyof T[K1][K2][K3][K4][K5],
K7 extends keyof T[K1][K2][K3][K4][K5][K6],
K8 extends keyof T[K1][K2][K3][K4][K5][K6][K7],
K9 extends keyof T[K1][K2][K3][K4][K5][K6][K7][K8]
>(
k1: K1,
k2: K2,
k3: K3,
k4: K4,
k5: K5,
k6: K6,
k7: K7,
k8: K8,
k9: K9
): BoundDocumentPathOfDepth9<T, K1, K2, K3, K4, K5, K6, K7, K8, K9>;
<
K1 extends keyof T,
K2 extends keyof T[K1],
K3 extends keyof T[K1][K2],
K4 extends keyof T[K1][K2][K3],
K5 extends keyof T[K1][K2][K3][K4],
K6 extends keyof T[K1][K2][K3][K4][K5],
K7 extends keyof T[K1][K2][K3][K4][K5][K6],
K8 extends keyof T[K1][K2][K3][K4][K5][K6][K7],
K9 extends keyof T[K1][K2][K3][K4][K5][K6][K7][K8],
K10 extends keyof T[K1][K2][K3][K4][K5][K6][K7][K8][K9]
>(
k1: K1,
k2: K2,
k3: K3,
k4: K4,
k5: K5,
k6: K6,
k7: K7,
k8: K8,
k9: K9,
k10: K10
): BoundDocumentPathOfDepth10<T, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10>;
}

export function $path<T>(): BoundDocumentPathCreator<T> {
// @ts-ignore surpress for typing.
return createDocumentPath;
}

export type NestedValue<
T,
export type NestedValue<T, K1, K2, K3, K4, K5, K6, K7, K8> = RawNestedValue<
DeepRequired<T>,
K1,
K2,
K3,
K4,
K5,
K6,
K7,
K8,
K9,
K10
> = RawNestedValue<DeepRequired<T>, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10>;
K8
>;

export type RawNestedValue<
T,
Expand All @@ -382,9 +260,7 @@ export type RawNestedValue<
K5,
K6,
K7,
K8,
K9,
K10
K8
> = K1 extends keyof T
? K2 extends keyof T[K1]
? K3 extends keyof T[K1][K2]
Expand All @@ -393,11 +269,7 @@ export type RawNestedValue<
? K6 extends keyof T[K1][K2][K3][K4][K5]
? K7 extends keyof T[K1][K2][K3][K4][K5][K6]
? K8 extends keyof T[K1][K2][K3][K4][K5][K6][K7]
? K9 extends keyof T[K1][K2][K3][K4][K5][K6][K7][K8]
? K10 extends keyof T[K1][K2][K3][K4][K5][K6][K7][K8][K9]
? T[K1][K2][K3][K4][K5][K6][K7][K8][K9][K10]
: T[K1][K2][K3][K4][K5][K6][K7][K8][K9]
: T[K1][K2][K3][K4][K5][K6][K7][K8]
? T[K1][K2][K3][K4][K5][K6][K7][K8]
: T[K1][K2][K3][K4][K5][K6][K7]
: T[K1][K2][K3][K4][K5][K6]
: T[K1][K2][K3][K4][K5]
Expand All @@ -412,27 +284,11 @@ type NullableByBoolean<T, B extends boolean> = B extends true
: T | null | undefined;

interface NestedValueGetter {
<
T extends Object,
B extends boolean,
K1,
K2,
K3,
K4,
K5,
K6,
K7,
K8,
K9,
K10
>(
<T extends Object, B extends boolean, K1, K2, K3, K4, K5, K6, K7, K8>(
obj: T,
path: BoundDocumentPath<T, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10>,
path: BoundDocumentPath<T, K1, K2, K3, K4, K5, K6, K7, K8>,
noNullAccess?: B
): NullableByBoolean<
NestedValue<T, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10>,
B
>;
): NullableByBoolean<NestedValue<T, K1, K2, K3, K4, K5, K6, K7, K8>, B>;
(obj: Object, path: string, noNullAccess?: boolean): any;
}

Expand Down
51 changes: 3 additions & 48 deletions modules/format/src/updating/bound-create-update-operation.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import {
BoundDocumentPath,
BoundDocumentPathOfDepth1,
BoundDocumentPathOfDepth10,
BoundDocumentPathOfDepth2,
BoundDocumentPathOfDepth3,
BoundDocumentPathOfDepth4,
BoundDocumentPathOfDepth5,
BoundDocumentPathOfDepth6,
BoundDocumentPathOfDepth7,
BoundDocumentPathOfDepth8,
BoundDocumentPathOfDepth9,
DeepRequired,
NestedValue,
} from "../common/bound-document-path";
Expand Down Expand Up @@ -203,51 +201,8 @@ export interface RawUpdateOperationCreator<OP extends UpdateOperator, T> {
value: ValueOf<OP, T[K1][K2][K3][K4][K5][K6][K7][K8]>
): BoundUpdateOperation<T, OP>;

<
K1 extends keyof T,
K2 extends keyof T[K1],
K3 extends keyof T[K1][K2],
K4 extends keyof T[K1][K2][K3],
K5 extends keyof T[K1][K2][K3][K4],
K6 extends keyof T[K1][K2][K3][K4][K5],
K7 extends keyof T[K1][K2][K3][K4][K5][K6],
K8 extends keyof T[K1][K2][K3][K4][K5][K6][K7],
K9 extends keyof T[K1][K2][K3][K4][K5][K6][K7][K8]
>(
docPath: BoundDocumentPathOfDepth9<T, K1, K2, K3, K4, K5, K6, K7, K8, K9>,
value: ValueOf<OP, T[K1][K2][K3][K4][K5][K6][K7][K8][K9]>
): BoundUpdateOperation<T, OP>;

<
K1 extends keyof T,
K2 extends keyof T[K1],
K3 extends keyof T[K1][K2],
K4 extends keyof T[K1][K2][K3],
K5 extends keyof T[K1][K2][K3][K4],
K6 extends keyof T[K1][K2][K3][K4][K5],
K7 extends keyof T[K1][K2][K3][K4][K5][K6],
K8 extends keyof T[K1][K2][K3][K4][K5][K6][K7],
K9 extends keyof T[K1][K2][K3][K4][K5][K6][K7][K8],
K10 extends keyof T[K1][K2][K3][K4][K5][K6][K7][K8][K9]
>(
docPath: BoundDocumentPathOfDepth10<
T,
K1,
K2,
K3,
K4,
K5,
K6,
K7,
K8,
K9,
K10
>,
value: ValueOf<OP, T[K1][K2][K3][K4][K5][K6][K7][K8][K9][K10]>
): BoundUpdateOperation<T, OP>;

<K1, K2, K3, K4, K5, K6, K7, K8, K9, K10>(
docPath: BoundDocumentPath<T, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10>,
value: ValueOf<OP, NestedValue<T, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10>>
<K1, K2, K3, K4, K5, K6, K7, K8>(
docPath: BoundDocumentPath<T, K1, K2, K3, K4, K5, K6, K7, K8>,
value: ValueOf<OP, NestedValue<T, K1, K2, K3, K4, K5, K6, K7, K8>>
): BoundUpdateOperation<T, OP>;
}
16 changes: 6 additions & 10 deletions modules/format/src/updating/bound-retarget-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,32 @@ export function $retarget<T>(): BoundRetarget<T> {

export interface BoundRetarget<T> {
<
U extends NestedValue<T, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10>,
U extends NestedValue<T, K1, K2, K3, K4, K5, K6, K7, K8>,
K1,
K2,
K3,
K4,
K5,
K6,
K7,
K8,
K9,
K10
K8
>(
docPath: BoundDocumentPath<T, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10>,
docPath: BoundDocumentPath<T, K1, K2, K3, K4, K5, K6, K7, K8>,
operation: BoundNonBreakingUpdateOperation<U>
): BoundNonBreakingUpdateOperation<T>;

<
U extends NestedValue<T, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10>,
U extends NestedValue<T, K1, K2, K3, K4, K5, K6, K7, K8>,
K1,
K2,
K3,
K4,
K5,
K6,
K7,
K8,
K9,
K10
K8
>(
docPath: BoundDocumentPath<T, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10>,
docPath: BoundDocumentPath<T, K1, K2, K3, K4, K5, K6, K7, K8>,
operation: BoundGeneralUpdateOperation<U>
): BoundGeneralUpdateOperation<T>;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
"nyc": "^13",
"rimraf": "^2.6.2",
"ts-node": "^7",
"typescript": "~3.2"
"typescript": "~3.4.1"
}
}

0 comments on commit 273926e

Please sign in to comment.