Skip to main content
Version: 2.8.y

Cursor

This section discusses how FirelordJS handle cursor empty rest parameter.

Empty Rest Parameter

Firestore throw if cursor has no argument, FirelordJS handle it by blocking all non-tuple type and empty tuple type.

same behavior apply to all other cursors

Why block empty tuple type?

Why block Empty Tuple Type?

Because Firestore will throw if cursor don't have any argument.

Why block Array Type?

In order to make certain rule typing work, FirelordJS need to know the position of each argument, array type does not hold such information.

What if the arguments is computed?

Unless it is properly typed**, most computed array is array type not tuple type hence it cannot pass the type check.

It is very rare to use computed array as cursor arguments, but if you really need it, then ignore the type error with // @ts-expect-error

Firestore admin will throw if the argument is an empty array, in such case Firelord will remove the cursor to avoid runtime error runtime error.

Example:

// @ts-expect-error
query(colRef, endAt()) // reduce to query(colRef)
// @ts-expect-error
query(colRef, endAt(...[])) // reduce to query(colRef)
const arr = someArr.map(() => {
//.....
})
// @ts-expect-error
query(colRef, endAt(...arr)) // only reduce to query(colRef) if arr is empty array

** Example of properly typed computed tuple

const concat = <T extends readonly unknown[], Y extends readonly unknown[]>(
arr1: T,
arr2: Y
) => {
return [...arr1, ...arr2] as [...T, ...Y]
}

concat([1, 2, 3], [4, 5, 6]) // number[]
concat([1, 2, 3] as const, [4, 5, 6] as const) // [1, 2, 3, 4, 5, 6]