From 1b2106e13bdbb617a5de332069bf8fb0f91a2b65 Mon Sep 17 00:00:00 2001 From: IZEM <59101683+izemomar@users.noreply.github.com> Date: Thu, 13 Apr 2023 06:41:59 +0000 Subject: [PATCH] fix(types/Column): infer lazy-loaded relations (#584) This commit updates the Column type to properly infer the relation properties of entities that use lazy loading, instead of inferring the properties of a Promise. This resolves an issue where the Column type would throw type errors when trying to access properties of the relation. --- src/helper.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/helper.ts b/src/helper.ts index a066f86..8e4c73b 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -9,6 +9,12 @@ type Join = K extends string type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...0[]] +// unwrap Promise type +type UnwrapPromise = T extends Promise ? UnwrapPromise : T + +// Unwrap Array type +type UnwrapArray = T extends Array ? UnwrapArray : T + // TODO: puts some comments here, in this ternary of doom export type Column = [D] extends [never] ? never @@ -18,7 +24,11 @@ export type Column = [D] extends [never] ? T[K] extends Date ? `${K}` : T[K] extends Array - ? `${K}` | Join> + ? `${K}` | Join, Prev[D]>> + : T[K] extends Promise + ? U extends Array + ? `${K}` | Join, Prev[D]>> + : `${K}` | Join, Prev[D]>> : `${K}` | Join> : never }[keyof T]