Skip to content

Commit 428f728

Browse files
authored
TypeScript: ResultSet extends AsyncIterable<Row>
Include `extends Iterable<Row>, AsyncIterable<Row>` in the TypeScript definition that is matched by the exiting JavaScript functionality.
1 parent 3edf1af commit 428f728

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

lib/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export namespace types {
319319
toString(): string;
320320
}
321321

322-
interface ResultSet extends Iterator<Row> {
322+
interface ResultSet extends Iterable<Row>, AsyncIterable<Row> {
323323
info: {
324324
queriedHost: string,
325325
triedHosts: { [key: string]: any; },

test/unit/typescript/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"module": "commonjs",
44
"lib": ["es2015"],
5-
"target": "es5",
5+
"target": "es2015",
66
"sourceMap": false,
77
"strict": true
88
},

test/unit/typescript/types-test.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,27 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { types } from "../../../index";
17+
import { types, Client } from "../../../index";
1818
import Uuid = types.Uuid;
1919
import TimeUuid = types.TimeUuid;
2020
import Long = types.Long;
2121
import BigDecimal = types.BigDecimal;
2222
import InetAddress = types.InetAddress;
2323
import Tuple = types.Tuple;
24+
import ResultSet = types.ResultSet;
25+
import Row = types.Row;
2426

2527
/*
2628
* TypeScript definitions compilation tests for types module.
2729
*/
2830

29-
function myTest(): void {
31+
async function myTest(): Promise<void> {
3032
let id:Uuid;
3133
let tid:TimeUuid;
3234
let b: boolean;
3335
let s: string;
3436
let buffer: Buffer;
37+
let rs: ResultSet;
3538

3639
types.protocolVersion.isSupported(types.protocolVersion.v4);
3740

@@ -61,4 +64,23 @@ function myTest(): void {
6164
long.div(long);
6265
// Use constructor
6366
long = new Long(1, 2);
67+
68+
const client = new Client({
69+
contactPoints: ['host1'],
70+
localDataCenter: 'dc1'
71+
});
72+
73+
rs = await client.execute('SELECT * FROM ks1.table1');
74+
// Test iteration
75+
for (const row of rs) {
76+
// Check is of type Row
77+
const r: Row = row;
78+
}
79+
80+
rs = await client.execute('SELECT * FROM ks1.table1');
81+
// Test async iteration
82+
for await (const row of rs) {
83+
// Check is of type Row
84+
const r: Row = row;
85+
}
6486
}

0 commit comments

Comments
 (0)