Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions typings/objection/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ declare namespace Objection {
[K in DataPropertyNames<T>]: T[K];
};

/**
* Returns keys that have function as their type.
*/
type KeysWithFunctionType<T> = {
[K in keyof T]: T[K] extends Function ? K : never;
}[keyof T];
Copy link
Collaborator

@lehni lehni Apr 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the reverse of the already existing NonFunctionPropertyNames, I think the name should reflect that:

FunctionPropertyNames


/**
* Like ModelObject, but preserves information about optionality.
*
* Removes keys that:
* - start with '$'
* - are 'QueryBuilderType'
* - have function type
*/
export type ModelProperties<T extends Model> = Pick<
T,
Exclude<keyof T, `$${string}` | 'QueryBuilderType' | KeysWithFunctionType<T>>
>;

/**
* Any object that has some of the properties of model class T match this type.
*/
Expand Down