snowflakedb / snowflake-connector-nodejs

NodeJS driver
Apache License 2.0
125 stars 133 forks source link

SNOW-1833760: Statement `hasNext` and `NextResult` are incorrectly typed #974

Open amardatar opened 4 days ago

amardatar commented 4 days ago

Apologies for omitting the standard questionnaire it's largely irrelevant. This is using version 1.15.0 of the driver.

The driver currently has the FileAndStageBindStatement methods hasNext and NextResult typed incorrectly, as functions that return functions. This is minor, but generates (for example) a linting warning like "Unnecessary conditional, value is always truthy." when attempting to call .hasNext().

For example, the following code shows a linting error:

const connection = snowflake.createConnection({ account: '' });
connection.execute({
    sqlText: 'select 1',
    complete(err, stmt, rows) {
        console.log(rows);
        // typescript-eslint will flag the `stmt.hasNext()` with `Unnecessary conditional, value is always truthy.`
        if ('hasNext' in stmt && stmt.hasNext()) {
            stmt.NextResult();
        }
    },
});

and instead expects to see stmt.hasNext()().

The issue seems to be here where the definitions have an extra set of parentheses. For validation, the source here returns a function, the result of which is assigned to this.hasNext.

sfc-gh-dszmolka commented 4 days ago

hi - thank you for pointing this out; and also for providing the details! we'll take a look.