From 273926e59fbd1de78d660ba96234aef98195e0a1 Mon Sep 17 00:00:00 2001 From: Shin Suzuki Date: Sat, 6 Apr 2019 16:19:38 +0900 Subject: [PATCH] fix(type): Reduce the number of type parameters Due to Microsoft/TypeScript/issues/30188 --- .../format/src/common/bound-document-path.ts | 170 ++---------------- .../updating/bound-create-update-operation.ts | 51 +----- .../src/updating/bound-retarget-operation.ts | 16 +- package.json | 2 +- 4 files changed, 23 insertions(+), 216 deletions(-) diff --git a/modules/format/src/common/bound-document-path.ts b/modules/format/src/common/bound-document-path.ts index 172f3b8..8ff7c3f 100644 --- a/modules/format/src/common/bound-document-path.ts +++ b/modules/format/src/common/bound-document-path.ts @@ -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, @@ -144,22 +111,8 @@ export type BoundDocumentPath< K5, K6, K7, - K8, - K9, - K10 -> = RawBoundDocumentPath< - DeepRequired, - K1, - K2, - K3, - K4, - K5, - K6, - K7, - K8, - K9, - K10 ->; + K8 +> = RawBoundDocumentPath, K1, K2, K3, K4, K5, K6, K7, K8>; type RawBoundDocumentPath< T, @@ -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] @@ -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 + ? BoundDocumentPathOfDepth8 : BoundDocumentPathOfDepth7 : BoundDocumentPathOfDepth6 : BoundDocumentPathOfDepth5 @@ -308,50 +232,6 @@ interface RawBoundDocumentPathCreator { k7: K7, k8: K8 ): BoundDocumentPathOfDepth8; - < - 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; - < - 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; } export function $path(): BoundDocumentPathCreator { @@ -359,8 +239,8 @@ export function $path(): BoundDocumentPathCreator { return createDocumentPath; } -export type NestedValue< - T, +export type NestedValue = RawNestedValue< + DeepRequired, K1, K2, K3, @@ -368,10 +248,8 @@ export type NestedValue< K5, K6, K7, - K8, - K9, - K10 -> = RawNestedValue, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10>; + K8 +>; export type RawNestedValue< T, @@ -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] @@ -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] @@ -412,27 +284,11 @@ type NullableByBoolean = B extends true : T | null | undefined; interface NestedValueGetter { - < - T extends Object, - B extends boolean, - K1, - K2, - K3, - K4, - K5, - K6, - K7, - K8, - K9, - K10 - >( + ( obj: T, - path: BoundDocumentPath, + path: BoundDocumentPath, noNullAccess?: B - ): NullableByBoolean< - NestedValue, - B - >; + ): NullableByBoolean, B>; (obj: Object, path: string, noNullAccess?: boolean): any; } diff --git a/modules/format/src/updating/bound-create-update-operation.ts b/modules/format/src/updating/bound-create-update-operation.ts index 60ada5a..4200ff2 100644 --- a/modules/format/src/updating/bound-create-update-operation.ts +++ b/modules/format/src/updating/bound-create-update-operation.ts @@ -1,7 +1,6 @@ import { BoundDocumentPath, BoundDocumentPathOfDepth1, - BoundDocumentPathOfDepth10, BoundDocumentPathOfDepth2, BoundDocumentPathOfDepth3, BoundDocumentPathOfDepth4, @@ -9,7 +8,6 @@ import { BoundDocumentPathOfDepth6, BoundDocumentPathOfDepth7, BoundDocumentPathOfDepth8, - BoundDocumentPathOfDepth9, DeepRequired, NestedValue, } from "../common/bound-document-path"; @@ -203,51 +201,8 @@ export interface RawUpdateOperationCreator { value: ValueOf ): BoundUpdateOperation; - < - 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, - value: ValueOf - ): BoundUpdateOperation; - - < - 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 - ): BoundUpdateOperation; - - ( - docPath: BoundDocumentPath, - value: ValueOf> + ( + docPath: BoundDocumentPath, + value: ValueOf> ): BoundUpdateOperation; } diff --git a/modules/format/src/updating/bound-retarget-operation.ts b/modules/format/src/updating/bound-retarget-operation.ts index 70ae4e2..6b31de1 100644 --- a/modules/format/src/updating/bound-retarget-operation.ts +++ b/modules/format/src/updating/bound-retarget-operation.ts @@ -13,7 +13,7 @@ export function $retarget(): BoundRetarget { export interface BoundRetarget { < - U extends NestedValue, + U extends NestedValue, K1, K2, K3, @@ -21,16 +21,14 @@ export interface BoundRetarget { K5, K6, K7, - K8, - K9, - K10 + K8 >( - docPath: BoundDocumentPath, + docPath: BoundDocumentPath, operation: BoundNonBreakingUpdateOperation ): BoundNonBreakingUpdateOperation; < - U extends NestedValue, + U extends NestedValue, K1, K2, K3, @@ -38,11 +36,9 @@ export interface BoundRetarget { K5, K6, K7, - K8, - K9, - K10 + K8 >( - docPath: BoundDocumentPath, + docPath: BoundDocumentPath, operation: BoundGeneralUpdateOperation ): BoundGeneralUpdateOperation; } diff --git a/package.json b/package.json index 406645d..690c7c4 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,6 @@ "nyc": "^13", "rimraf": "^2.6.2", "ts-node": "^7", - "typescript": "~3.2" + "typescript": "~3.4.1" } }