nodejs-datastore icon indicating copy to clipboard operation
nodejs-datastore copied to clipboard

Unable to filter property with null value

Open mlev opened this issue 3 years ago • 0 comments

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.

mlev avatar Jun 24 '22 13:06 mlev