Skip to content

Commit 9a7bc0b

Browse files
committed
fix type
1 parent c7f4170 commit 9a7bc0b

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

packages/hypergraph/src/entity/create.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@ import { findOne } from './findOne.js';
1010
import type { DocumentContent, DocumentRelation, Entity } from './types.js';
1111

1212
/**
13-
* Type utility to transform relation fields to accept string arrays instead of their typed values
14-
* This specifically targets Type.Relation fields which are arrays of objects
15-
* Relations can be provided as string arrays or left out completely (optional)
13+
* Type utility to transform relation fields to accept string arrays or be omitted entirely.
14+
* This specifically targets Type.Relation fields which are arrays of objects.
1615
*/
17-
type WithRelationsAsStringArrays<T> = {
16+
type RelationArrayKeys<T> = {
1817
[K in keyof T]: T[K] extends readonly (infer U)[]
1918
? U extends object
20-
? string[] | undefined
21-
: T[K]
19+
? K
20+
: never
2221
: T[K] extends (infer U)[]
2322
? U extends object
24-
? string[] | undefined
25-
: T[K]
26-
: T[K];
27-
};
23+
? K
24+
: never
25+
: never;
26+
}[keyof T];
27+
28+
type WithRelationsAsStringArrays<T> = Omit<T, RelationArrayKeys<T>> &
29+
Partial<Record<RelationArrayKeys<T>, string[] | undefined>>;
2830

2931
export const create = <const S extends Schema.Schema.AnyNoContext>(handle: DocHandle<DocumentContent>, type: S) => {
3032
return (data: Readonly<WithRelationsAsStringArrays<Schema.Schema.Type<S>>>): Entity<S> => {

0 commit comments

Comments
 (0)