Typed static queries

I'm opening this PR so we can discuss the current state of the implementation.
hasPath is what I meant. Looks like this should be applicable here. I'm using it for the same kind of code.