Skip to content

Unable to filter property with null value #958

@mlev

Description

@mlev

Environment details

  • OS: MacOS
  • Node.js version: 16.15.0
  • npm version: 8.5.5
  • @google-cloud/datastore version: 7.0.0

Steps to reproduce

Not sure if I'm missing something but currently any attempt to query by a value that might be null will result in TS error Type 'null' is not assignable to type '{}'.
e.g.

  const queryByStatus = (status: string | null) => {
    // Without operator
    const query1 = datastore.createQuery(kind).filter("status", status);
    // With operator
    const query2 = datastore.createQuery(kind).filter("status", "=", status);
  };

This is because the typings for Query.filter do not allow passing a null value:

filter(property: string, value: {}): Query;
filter(property: string, operator: Operator, value: {}): Query;

Note the workaround is to use the non-null operator ! on the value but this isn't ideal.

Metadata

Metadata

Assignees

Labels

api: datastoreIssues related to the googleapis/nodejs-datastore API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions