tien commented on PR #2599:
URL: https://github.com/apache/tinkerpop/pull/2599#issuecomment-2118834748
I mainly included the utility function as a demonstration of what a strong
TypeScript definition can enable.
As for the benefit of having an utility function like that, with TypeScript
I have to do a lot of boilerplates just extract basic values from vertices, i.e:
```ts
const vertices = await g.V().hasLabel("person").toList<PersonVertex>();
const people = vertices.map(vertex => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const age = vertex.properties.age.at(0)!.value;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const name = vertex.properties.name.at(0)!.value;
const addresses = vertex.properties.address.map(x => x.value);
return {
age,
name,
addresses
};
});
```
which with the utility function can be simplified to
```ts
const vertices = await g.V().hasLabel("person").toList<PersonVertex>();
const people = vertices.map(vertex => parseVertex(vertex, { address: "list"
}));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]