Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(orm): exclude function fields from FieldName type
Browse files Browse the repository at this point in the history
Char2sGu committed May 18, 2022
1 parent e135620 commit e249771
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/orm/src/utils.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ import { getInstanceStateFromItem } from './identity-map';
import { getClassTypeFromInstance } from '@deepkit/core';

export type FlattenIfArray<T> = T extends Array<any> ? T[0] : T;
export type FieldName<T> = keyof T & string;
export type FieldName<T> = { [Key in keyof T & string]: T[Key] extends Function ? never : Key }[keyof T & string];

export function getClassSchemaInstancePairs<T extends OrmEntity>(items: Iterable<T>): Map<ReflectionClass<any>, T[]> {
const map = new Map<ReflectionClass<any>, T[]>();
3 changes: 2 additions & 1 deletion packages/orm/tests/query.spec.ts
Original file line number Diff line number Diff line change
@@ -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<T extends { username: string }> extends MyBase<T> {
findAllUserNames() {
return this.findField('username');
return this.findField('username' as FieldName<T>);
}

//query classes should be able to infer the actual used class

0 comments on commit e249771

Please sign in to comment.