Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1789882: Accept readonly arrays as Binds #949

Open
omerchn opened this issue Nov 6, 2024 · 1 comment
Open

SNOW-1789882: Accept readonly arrays as Binds #949

omerchn opened this issue Nov 6, 2024 · 1 comment
Assignees
Labels
enhancement The issue is a request for improvement or a new feature status-triage_done Initial triage done, will be further handled by the driver team

Comments

@omerchn
Copy link

omerchn commented Nov 6, 2024

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!

@omerchn omerchn added the bug Something isn't working label Nov 6, 2024
@github-actions github-actions bot changed the title Accept readonly arrays as Binds SNOW-1789882: Accept readonly arrays as Binds Nov 6, 2024
@sfc-gh-dszmolka
Copy link
Collaborator

hi - thank you for the suggestion on the enhancement, we'll consider for future plans.

@sfc-gh-dszmolka sfc-gh-dszmolka added enhancement The issue is a request for improvement or a new feature status-triage_done Initial triage done, will be further handled by the driver team and removed bug Something isn't working labels Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is a request for improvement or a new feature status-triage_done Initial triage done, will be further handled by the driver team
Projects
None yet
Development

No branches or pull requests

3 participants