surrealdb / surrealdb.js

SurrealDB SDK for JavaScript
https://surrealdb.com
Apache License 2.0
272 stars 45 forks source link

Bug: Missing typing on `.query` method #240

Closed OTheNonE closed 2 months ago

OTheNonE commented 3 months ago

Describe the bug

The generic type T is not used in the return of the .query function:

/**
 * Runs a set of SurrealQL statements against the database.
 * @param query - Specifies the SurrealQL statements.
 * @param bindings - Assigns variables which can be used in the query.
 */
async query<T extends unknown[]>(
    query: string | PreparedQuery,
    bindings?: Record<string, unknown>,
) {
    const raw = await this.query_raw<T>(query, bindings);
    return raw.map(({ status, result }) => {
        if (status == "ERR") throw new ResponseError(result);
        return result;
    });
}

This makes it so that i get no types on my result.

Steps to reproduce

Use the latest current version of surrealdb.js and try to specify a type for the .query function.

Expected behaviour

Exptected the result from the function to be of the specified generic type.

SurrealDB version

surreal 1.4.2 for windows

SurrealDB.js version

1.0.0-beta.5

Contact Details

olavnon@gmail.com

Is there an existing issue for this?

Code of Conduct