From e31b1ff5449cd1bdf252e112a38b1ff5a8f40764 Mon Sep 17 00:00:00 2001 From: avallete Date: Tue, 22 Oct 2024 11:57:18 +0200 Subject: [PATCH] fix: unwrap error within arrays --- src/select-query-parser/utils.ts | 16 ++++++++++------ test/select-query-parser/select.test-d.ts | 5 ++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/select-query-parser/utils.ts b/src/select-query-parser/utils.ts index 5a7c0abf..804632dd 100644 --- a/src/select-query-parser/utils.ts +++ b/src/select-query-parser/utils.ts @@ -10,12 +10,6 @@ import { UnionToArray, } from './types' -export type UnwrapErrorMessages = T extends SelectQueryError - ? M - : T extends Record - ? { [K in keyof T]: UnwrapErrorMessages } - : T - export type SelectQueryError = { error: true } & Message type RequireHintingSelectQueryError< @@ -23,6 +17,16 @@ type RequireHintingSelectQueryError< RelationName extends string > = SelectQueryError<`Could not embed because more than one relationship was found for '${DistantName}' and '${RelationName}' you need to hint the column with ${DistantName}! ?`> +export type UnwrapErrorMessages = T extends SelectQueryError + ? M + : T extends SelectQueryError[] + ? M[] + : T extends (infer U)[] + ? UnwrapErrorMessages[] + : T extends Record + ? { [K in keyof T]: UnwrapErrorMessages } + : T + export type GetFieldNodeResultName = Field['alias'] extends string ? Field['alias'] : Field['aggregateFunction'] extends AggregateFunctions diff --git a/test/select-query-parser/select.test-d.ts b/test/select-query-parser/select.test-d.ts index 0001e6db..af57519b 100644 --- a/test/select-query-parser/select.test-d.ts +++ b/test/select-query-parser/select.test-d.ts @@ -1,7 +1,6 @@ import { expectType } from 'tsd' import { TypeEqual } from 'ts-expect' import { Json } from '../../src/select-query-parser/types' -import { SelectQueryError } from '../../src/select-query-parser/utils' import { Prettify } from '../../src/types' import { Database } from '../types' import { selectQueries } from '../relationships' @@ -271,7 +270,7 @@ type Schema = Database['public'] id: number second_user: string third_wheel: string | null - first_user: SelectQueryError<"Could not embed because more than one relationship was found for 'users' and 'best_friends' you need to hint the column with users! ?"> + first_user: "Could not embed because more than one relationship was found for 'users' and 'best_friends' you need to hint the column with users! ?" }> second_friend_of: Array third_wheel_of: Array @@ -440,7 +439,7 @@ type Schema = Database['public'] let result: Exclude let expected: { username: string - messages: SelectQueryError<"column 'sum' does not exist on 'messages'.">[] + messages: "column 'sum' does not exist on 'messages'."[] } expectType>(true) }