#6528·knex

Allow `readonly string[]` for `withRecursive` column names

Author: TiAlRoCreated Sep 3, 2026Updated Sep 3, 2026

Description

The TypeScript definition for withRecursive currently requires the column names parameter to be a mutable string[].

The relevant type is WithWrapped, where this parameter is currently typed as string[]. Since the column names array does not need to be mutated, it could accept readonly string[] instead.

For example:

const columns = ['id', 'parent_id'] as const;

knex.withRecursive('tree', columns, (qb) => {
  // ...
});

Currently, the readonly tuple cannot be passed because it is not assignable to string[].

Expected behavior

withRecursive should accept readonly arrays and tuples:

const columns = ['id', 'parent_id'] as const;

knex.withRecursive('tree', columns, (qb) => {
  // ...
});

Proposed change

Change the column names parameter in WithWrapped from:

string[]

to:

readonly string[]

This is backwards compatible with existing callers using string[] and allows callers to pass readonly arrays without a cast or mutable copy.

A TypeScript test covering a readonly tuple such as ['id', 'parent_id'] as const should be added.