ROS TypeScript Generator

1.10.0 · active · verified Sun Apr 19

ros-typescript-generator is a Command Line Interface (CLI) tool designed to generate TypeScript interfaces and enums directly from ROS (Robot Operating System) message (`.msg`), service (`.srv`), and action (`.action`) definition files. Currently at version 1.10.0, this package sees active development with several minor releases annually, often introducing new features and bug fixes. A key differentiator is its focus on generating pure TypeScript types without any runtime dependencies or classes in the output, making it an ideal choice for frontend applications or any project requiring only type definitions. It supports both ROS1 and ROS2 message formats and offers configurable output options like type prefixes, namespaces, and 'smart enums', setting it apart from alternatives that might include Node.js-specific runtime components.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates the typical CLI usage by providing a sample configuration file and the command to run the generator, along with a brief illustration of using the resulting TypeScript types.

{
  "output": "./generated/ros_msgs.ts",
  "rosVersion": 2,
  "typePrefix": "IRosType",
  "useNamespaces": false,
  "smartEnums": true,
  "input": [
    {
      "namespace": "std_msgs",
      "path": "/opt/ros/iron/share/std_msgs"
    },
    {
      "namespace": "geometry_msgs",
      "path": "/opt/ros/iron/share/geometry_msgs"
    }
  ]
}

// 1. Save the above JSON content into a file named `ros-ts-generator-config.json` in your project root.

// 2. Run the generator using npx:
npx ros-typescript-generator --config ros-ts-generator-config.json

// 3. Example of how to use the generated types in your TypeScript project (e.g., in `src/app.ts`):
// import { IRosTypeStdMsgsHeader } from './generated/ros_msgs';

// const myHeader: IRosTypeStdMsgsHeader = {
//   seq: 10,
//   stamp: { sec: 1678886400, nanosec: 500000000 },
//   frame_id: 'robot_base'
// };

// console.log('Generated ROS Header:', myHeader);

view raw JSON →