From e2497718e236af76de3f5a98f1c4424650cc1d26 Mon Sep 17 00:00:00 2001 From: Char2s Date: Thu, 19 May 2022 00:53:00 +0800 Subject: [PATCH] feat(orm): exclude function fields from `FieldName` type --- packages/orm/src/utils.ts | 2 +- packages/orm/tests/query.spec.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/orm/src/utils.ts b/packages/orm/src/utils.ts index 6842ee353..8b61c876a 100644 --- a/packages/orm/src/utils.ts +++ b/packages/orm/src/utils.ts @@ -16,7 +16,7 @@ import { getInstanceStateFromItem } from './identity-map'; import { getClassTypeFromInstance } from '@deepkit/core'; export type FlattenIfArray = T extends Array ? T[0] : T; -export type FieldName = keyof T & string; +export type FieldName = { [Key in keyof T & string]: T[Key] extends Function ? never : Key }[keyof T & string]; export function getClassSchemaInstancePairs(items: Iterable): Map, T[]> { const map = new Map, T[]>(); diff --git a/packages/orm/tests/query.spec.ts b/packages/orm/tests/query.spec.ts index 507fc1834..79f3bfdbe 100644 --- a/packages/orm/tests/query.spec.ts +++ b/packages/orm/tests/query.spec.ts @@ -4,6 +4,7 @@ import { assert, IsExact } from 'conditional-type-checks'; import { Database } from '../src/database'; import { MemoryDatabaseAdapter, MemoryQuery } from '../src/memory-db'; import { Query } from '../src/query'; +import { FieldName } from "../src/utils"; test('query select', async () => { class s { @@ -54,7 +55,7 @@ test('query lift', async () => { class UserQuery extends MyBase { findAllUserNames() { - return this.findField('username'); + return this.findField('username' as FieldName); } //query classes should be able to infer the actual used class