Skip to content

Cannot properly type query return. #182

@brvnonascimento

Description

@brvnonascimento

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
  }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions