In my code, I am attempting to create a generic function that abstracts my repository infrastructure for creating a where clause.
export type DeepPartial<T> = T extends object
? {
[P in keyof T]?: DeepPartial<T[P]>;
}
: T;
export interface SearchOneOptions<ENTITY extends { id: string }> {
/** Names of object attributes nested in the result object that must be filled, if possible */
includeNested?: string[];
/** Entities that can be soft deleted won't appear in queries by default */
withDeleted?: boolean;
select?: string[];
where?: DeepPartial<ENTITY>
}
const b = <T extends { id: string }>(t: T) => {
const a: SearchOneOptions<T> = {
where: {
id: t.id
}
}
}
However, I encounter this error message:
Type '{ id: string; }' is not assignable to type 'DeepPartial<T>'.
Try it out on TypeScript Playground
Can anyone help me resolve this issue? Thank you so much :)