cypher-query-builder
cypher-query-builder copied to clipboard
Cannot specify query return type with strict keys
Because the generic passed to run/stream/first
is wrapped in a Dictionary
, I cannot specify the object being returned.
For example,
const orgFromNode = (node: Node<Organization>) =>
Organization.from(node.properties);
const orgNode = await q
.matchNode('org', 'Organization')
.return('org')
.first();
return orgFromNode(orgNode);
TS2345: Argument of type 'Dictionary<any>' is not assignable to parameter of type 'Node<Organization>'.
Type 'Dictionary<any>' is missing the following properties from type 'Node<Organization>': identity, labels, properties
IMO, Dictionary
types are pretty worthless since you can't specify their associated keys. All keys could be any of the value types.
const record = {} as Dictionary<string | boolean | DateTime>;
record.updatedAt; // this a DateTime but TS thinks it could be a boolean or string as well
record.active; // this a boolean but TS thinks it could be a DateTime or string as well
It would be helpful if this wrapping is removed so one can specify the actual return type. i.e.
const orgNode = await q
.matchNode('org', 'Organization')
.return('org')
.first<Node<Organization>>()
And Dictionary
types could still be used by users, just explicitly now.
I know this is probably considered a breaking change 🙁
On a positive note, I'm loving the library and it's design. Thanks for your hard work 🤝
Thanks for the feedback. This is something that I have wanted to fix for a while but never got around to doing it. I'll make sure the fix is in the next major release.
Awesome thanks man 👍