Bug #109189 Typescript Session.Schema.Table.select(): declaration is missing arguments
Submitted: 24 Nov 2022 7:11 Modified: 15 Feb 2023 22:35
Reporter: sesi ye Email Updates:
Status: Closed Impact on me:
Category:Connector for Node.js Severity:S3 (Non-critical)
Version:8.0.31 OS:Any
Assigned to: Rui Quelhas CPU Architecture:Any
Tags: declaratior, typescript

[24 Nov 2022 7:11] sesi ye
Using mysqlx connector 8.0.31 with typescript and nodejs,
if Table.select() is supplied arguments, typescript will
not compile as it expects no arguments, or, if
Table.select() is not supplied with any argument,
executing the statement will throw Error: Unknown column 
'doc' in 'field list'.

The problem comes from a wrong declaration of Table's
select in "@mysql/xdevapi/types/lib/DevApi/Table.d.ts".

tested with nodejs 16LTS & typescript 4.9.3.

How to repeat:
1. spin a mysql 8.x instance
2. mkdir testdir && cd testdir
3. npm --init && npm i typescript ts-node @mysql/xdevap
4. tsc --init (and set for your environment)
5. (see index.ts after) adapt the demo script from https://dev.mysql.com/doc/x-devapi-userguide/en/devapi-users-working-with-relational-table...
6. Notice TS IDE error messages for select() arguments
7. Notice compile errors if you run "tsc" or "npx tsc"
8. Delete select() arguments, IDE error is gone, compile is ok.
9. Notice runtime error if you run "ts-node index.ts"

Adapted demo script:

import mysqlx from "@mysql/xdevapi";

(async function () {
  const session = await mysqlx.getSession({
    user: "user",
    password: "password",
    host: "localhost",
    port: 33060
  const myTable = session.getSchema("test").getTable("my_table");

  // Insert SQL Table data
  await myTable
    .insert(["name", "birthday", "age"])
    .values(["Laurie", "2000-5-27", 19])

  const myResult = await myTable
    .select(["_id", "name", "birthday"])
    .where("name like :name && age < :age)")
    .bind("name", "L%")
    .bind("age", 30)


Suggested fix:

80 -
    select: () => TableSelect
80 + 
    select: (...v:any[]) => TableSelect
[4 Jan 2023 17:44] Rui Quelhas
Posted by developer:
Hi sesi,

Thank you for your bug report. You are correct, the TypeScript definition for Table.select() is missing the argument specification and corresponding types. It clearly needs to be fixed.
[15 Feb 2023 22:35] Philip Olson
Posted by developer:
Fixed as of the upcoming MySQL Connector/Node.js 8.0.33 release, and here's the proposed changelog entry from the documentation team:

The Table.select() method's TypeScript definition did not specify
possible argument types; and this resulted in an error when the TypeScript
compiler (tsc) compiled the application code to JavaScript. 

Thank you for the bug report.