Skip to content

Type of value is incorrect (Type is any, should be more specific) #3982

@uPaymeiFixit

Description

@uPaymeiFixit

The type of execute's values parameter is any (so basically no type definition). Admittedly I'm not 100% sure I've found all the possibilities for what values can be, but I do know if you pass in an undefined value (for example connection.execute("SELECT 1 + ? + ?", [1, 2, undefined, 4]); it will throw an error.

I've noticed LLMs are pretty good at adhering to type definitions, but love to take advantage of the any here. Almost got us into trouble at work. How do we feel about using something like the following definition, which is as close a definition I can think of for "any, except undefined or an array with undefined".

type Value =
  | string                    // <-- primitive
  | number                    // <-- primitive
  | boolean                   // <-- primitive
  | symbol                    // <-- primitive
  | bigint                    // <-- primitive
  | null                      // <-- primitive
  | Record<string, unknown>   // <-- Object
  | ({} | null)[];            // <-- (any - undefined) array

I'll create a PR if this (or something else) looks good.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions