TypeScript incomplete declaration of Traverser

This is a bit of a small (and probably dumb) question, as I'm new to TypeScript. I'm having trouble compiling my TypeScript code, translating it from Javascript. I see that toList returns an instance of Promise<Traverse[]>, which is fine and dandy, but it looks like several bits of documentation have get as an method to retrieve a specific object.
const { graph: orgDb, client: nClient } = connectNeptune();
const dept_and_div = (await orgDb.V().has('email', "[email protected]")
.inE('manages').outV().valueMap()
.with_(WithOptions.tokens).by(__.unfold()).toList());
for (const item of dept_and_div) {
if (item.get(T.label) === 'organization') {
//.........
const { graph: orgDb, client: nClient } = connectNeptune();
const dept_and_div = (await orgDb.V().has('email', "[email protected]")
.inE('manages').outV().valueMap()
.with_(WithOptions.tokens).by(__.unfold()).toList());
for (const item of dept_and_div) {
if (item.get(T.label) === 'organization') {
//.........
However, I see in the types.d.ts file that there is no such thing, even though 1) https://tinkerpop.apache.org/javadocs/current/full/org/apache/tinkerpop/gremlin/process/traversal/Traverser.html#get() does have a get function within its available methods. and 2) The way I intended to use it is that I wanted to retrieve the specific vertex and cast it into a Map object as I have done when it was in JavaScript, but it couldn't work out that way due to these issues.
class Traverser {
constructor(object: any, bulk?: number);
}
class Traverser {
constructor(object: any, bulk?: number);
}
Is there a specific TypeScript file or mechanic that I'm missing?
2 Replies
danielcraig23
danielcraig232w ago
I have the same issue: how do I get() anything from a Traverser? I'm able to cast it like this: const castResult : Map<string, string> = result as Map<string, string>
Kennh
Kennh2w ago
It seems like you are using the type definitions provided from DefinitelyTyped in this question. These definitions haven't been updated for a while so it could be missing items. TypeScript will be supported better in the next major version (4.0.0) as the TypeScript definitions will be maintained within the TinkerPop repo. Does using the as syntax suggested above solve your problem?

Did you find this page helpful?