jamesfer / cypher-query-builder

An flexible and intuitive query builder for Neo4j and Cypher.
http://jamesfer.me/cypher-query-builder/index.html
MIT License
104 stars 22 forks source link

Cannot properly type query return. #182

Open brvnonascimento opened 3 years ago

brvnonascimento commented 3 years ago

When passing a generic to query.run() it does not properly type the returned value. It's typed as a Dictionary[], but when I try to access one of its elements it's not compatible with the previous given type.

import { Connection, node, Node } from 'cypher-query-builder';

type UserNode = Node<{
  email: string;
}>;

//
export class UserRepo implements IUserRepo {
 // ...

 async findUserByEmail(email: string): Promise<User | null> {
    const query = this.cypher.match([node('user', 'User', { email })]);

    const rawUser = await query.run<UserNode>();
    // TYPED AS: Dictionary<UserNode>[]

    return UserMapper.toDomain(rawUser[0].properties);
   // rawUser[0].properties is typed as any
  }

}