Skip to content

Commit 5acead1

Browse files
committed
feat(builder): Return type hint for return object
1 parent 1ec540c commit 5acead1

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/builder.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,9 @@ export abstract class Builder
741741
* @param definition - definition of return object as key value pair whereas value can be
742742
* string selector or @see Selector
743743
*
744+
* @typeParam N - (optional) new target type of this cypher to hint the keys that you want
745+
* to be sure of
746+
*
744747
* @example
745748
* ```typescript
746749
* // Selector Object:
@@ -752,7 +755,7 @@ export abstract class Builder
752755
*
753756
* ```typescript
754757
* // String selector
755-
* q.returnObject({ user: 'person.name' });
758+
* q.returnObject<{user: any}>({ user: 'person.name' });
756759
* ```
757760
*
758761
* ```typescript
@@ -763,10 +766,10 @@ export abstract class Builder
763766
* ])
764767
* ```
765768
*/
766-
returnObject(
767-
definition: Many<Selectable<G>>,
769+
returnObject<N = unknown>(
770+
definition: Many<Selectable<G, StringKeyOf<N>>>,
768771
) {
769-
return this.continueChainClause(new ReturnObject(definition));
772+
return this.continueChainClause(new ReturnObject(definition)) as any as Query<N>;
770773
}
771774

772775
/**

src/clauses/returnObject.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { Clause } from '../clause';
22
import { Many, isArray } from 'lodash';
33
import { Selector } from '../selector';
44

5-
export type Selectable<G> = Record<string, string | Selector<G> | Record<string, Selector<G>>>;
5+
/**
6+
* @typeParam G - (optional) current graph model to gather data drom
7+
* @typeParam T - (optional) Target type that defines the output
8+
*/
9+
export type Selectable<G, T extends string = string>
10+
= Record<T, string | Selector<G> | Record<T, Selector<G>>>;
611

712
/**
813
* Clause to create an object formed RETURN

0 commit comments

Comments
 (0)