Cannot specify `null` as default value for `Select` in JS driver with TypeScript

In FQL, it is possible to specify null as the default value returned by Select. In the example below, null is returned if the matched document doesn’t have a user field:

    ["data", "user"],
    Get(Match(Index("unique_Identity_id"), CurrentIdentity())),

However the type annotations for the JS driver do not allow you to specify null:

type ExprVal = Expr | string | number | boolean | { [key: string]: any }
type ExprArg = ExprVal | Array<ExprVal>
export function Select(path: ExprArg, from: ExprArg, _default?: ExprArg): Expr


With the example above, this is what would happen:

      ["data", "user"],
      Get(Match(Index("unique_Identity_id"), CurrentIdentity())),
//    ^^^^
// Argument of type 'null' is not assignable
// to parameter of type 'ExprArg | undefined'.

TypeScript Playground

Is the type annotation correct or intentional?

null is a valid value in a lot of places, including add a default value for Select. In this case, the Typescript type is wrong.

If is another function that should be able to accept null in its arguments. Similar to how If's type was updated, the type of Select should be also be updated. (I guess I should have argued harder to update Select at the same time back then :sweat_smile: )

I’ve created a Github issue.

1 Like

Awesome, thanks for confirming and creating the issue!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.