TypeScript Support in the DataStax Node.js Drivers
I'm happy to announce built-in TypeScript support in our DataStax Node.js drivers for Apache Cassandra and DataStax Enterprise Node.js Driver.
TypeScript declarations of the driver are now contained in the same package and repository. These declarations will be maintained and kept in sync along with the JavaScript API.
Additionally, you can now use DSE-specific types like geo, auth and graph types from TypeScript.
Getting started
To get started with the Node.js driver for Apache Cassandra in a TypeScript project, install the driver package:
npm install cassandra-driver
... and you are all set to start coding in TypeScript!
For example, create a simple script to connect and retrieve a single row:
import { Client } from "cassandra-driver";
async function run() {
const client = new Client({
contactPoints: ['127.0.0.1'],
localDataCenter: 'datacenter1'
});
await client.connect();
const rs = await client.execute('SELECT * FROM system.local');
const row = rs.first();
console.log(`Connected to cluster: ${row['cluster_name']}`);
await client.shutdown();
}
run();
Compile and run it:
tsc my-file.ts && node my-file.js
You can continue reading here on how to get started with the Node.js drivers.
Acknowledgements
We would like to thank Michał Kamiński, Christian D and the rest of the community for an excellent job maintaining the driver definitions at DefinitelyTyped project, enabling TypeScript developers to use Apache Cassandra and DSE.
Wrapping up
We hope you enjoy using the driver from TypeScript projects!
If you are updating from community definitions, feel free to remove the @types dependency.
You can get the latest versions of the driver on the npm registry:
https://www.npmjs.com/package/cassandra-driver
https://www.npmjs.com/package/dse-driver