Skip to content

SNOW-1789882: Accept readonly arrays as Binds #949

Open
@omerchn

Description

Version: [email protected]

Currently, Binds are typed as followed:

export type Bind = string | number;
export type InsertBinds = Bind[][];
export type Binds = Bind[] | InsertBinds;

So if I have an array that is typed as a ReadonlyArray:

const binds = ['some', 'value'] as const
// or
const binds: readonly string[] = ['some', 'value']
// or in my case, I use Knex.js to construct queries and pass binds from knex into the sdk. knex binds are typed as readonly.
const binds = sql.toSQL().bindings

I get the following type error:

Type 'readonly string[]' is not assignable to type 'Binds | undefined'.
  The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'InsertBinds'.

Technically, there should not be an issue with accepting a readonly array, It's only a TypeScript construct and in JavaScript's view it's a just normal array.

I suggest changing the types to be as followed:

type ArrayOrReadonlyArray<T> = T[] | readonly T[];
export type InsertBinds = ArrayOrReadonlyArray<ArrayOrReadonlyArray<Bind>>;
export type Binds = ArrayOrReadonlyArray<Bind> | InsertBinds;

Thank you!

Metadata

Labels

enhancementThe issue is a request for improvement or a new featurestatus-triage_doneInitial triage done, will be further handled by the driver team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions