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.
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.
Is there a specific TypeScript file or mechanic that I'm missing?2 Replies
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>
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?