Skip to content

Latest commit

History

History
45 lines (31 loc) · 1.25 KB

File metadata and controls

45 lines (31 loc) · 1.25 KB

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';constttypes=require('./thrift/generated/client_types');asyncfunctionexample(){constsession=newSession({host: 'localhost',port: 6667,username: 'root',password: 'root'});awaitsession.open();// TypeScript provides autocomplete and type checkingconstresult=awaitsession.executeQueryStatement('SELECT * FROM root.test');// TypeScript knows result.columns is string[]result.columns.forEach(col=>console.log(col.toUpperCase()));awaitsession.close();}

Migration from JavaScript

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