TypeScript Support Examples

This document demonstrates the TypeScript support in the IoTDB Node.js client.

Full Type Safety with Thrift Types

With the TypeScript declaration files, you get complete type safety when working with Thrift-generated types.

Benefits

  • ✅ Full IntelliSense and autocomplete in VS Code/WebStorm
  • ✅ Compile-time type checking for all Thrift types
  • ✅ Better refactoring support
  • ✅ Self-documenting code
  • ✅ Zero runtime overhead (.d.ts files are compile-time only)

Example Usage

import { Session } from './client/Session';
const ttypes = require('./thrift/generated/client_types');

async function example() {
  const session = new Session({
    host: 'localhost',
    port: 6667,
    username: 'root',
    password: 'root'
  });

  await session.open();

  // TypeScript provides autocomplete and type checking
  const result = await session.executeQueryStatement('SELECT * FROM root.test');
  
  // TypeScript knows result.columns is string[]
  result.columns.forEach(col => console.log(col.toUpperCase()));

  await session.close();
}

Migration from JavaScript

Existing JavaScript code continues to work without changes. The .d.ts files provide optional type information for TypeScript users.