From 85c852929d50b70b03da0f142a0acb5f048d1c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Kl=C3=ADma?= Date: Wed, 29 Nov 2023 10:49:09 +0100 Subject: [PATCH] Improved lens find interface output type (#77) --- library/lens/lens.ts | 4 ++-- library/lens/types.ts | 8 +++++--- library/schema/interface.ts | 11 +---------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/library/lens/lens.ts b/library/lens/lens.ts index 888e8d4..cb7bebc 100644 --- a/library/lens/lens.ts +++ b/library/lens/lens.ts @@ -11,7 +11,7 @@ import { import { decode } from "../decoder.ts"; import { QueryBuilder } from "./query_builder.ts"; -import type { Entity } from "./types.ts"; +import type { Entity, Unite } from "./types.ts"; import { QueryEngineProxy } from "../engine/query_engine_proxy.ts"; /** @@ -58,7 +58,7 @@ export class Lens< } private decode(graph: Graph) { - return decode(graph, this.schema, this.context) as unknown as I[]; + return decode(graph, this.schema, this.context) as unknown as Unite[]; } async count() { diff --git a/library/lens/types.ts b/library/lens/types.ts index 6f6831d..48bc815 100644 --- a/library/lens/types.ts +++ b/library/lens/types.ts @@ -1,11 +1,13 @@ import type { SchemaInterfaceIdentity } from "../schema/mod.ts"; -export type Entity< - T extends unknown = Record, -> = +export type Entity> = & DeepPartial & SchemaInterfaceIdentity; export type DeepPartial = T extends Record ? { [P in keyof T]?: DeepPartial } : T; + +export type Unite = T extends Record + ? { [Key in keyof T]: T[Key] } + : T; diff --git a/library/schema/interface.ts b/library/schema/interface.ts index 8c9fc18..e6277f3 100644 --- a/library/schema/interface.ts +++ b/library/schema/interface.ts @@ -1,16 +1,7 @@ import type { SupportedDataTypes } from "./data_types.ts"; import type { PropertyPrototype, SchemaPrototype } from "./schema.ts"; -type Prettify = - & { - [K in keyof T]: T[K]; - } - // deno-lint-ignore ban-types - & {}; - -type Unite = T extends Record ? { - [Key in keyof T]: T[Key]; - } +type Unite = T extends Record ? { [Key in keyof T]: T[Key] } : T; type IsOptional = Property extends {