Registry / data / ros-typescript-generator

ros-typescript-generator

JSON →
library1.10.0jsnpmunverified

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.

npm install ros-typescript-generator
INSTALL
IMPORT
SIG · ROS-TYPESCRIPT-GEN
R
ros-typescript-generator
datajavascriptv1.10.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

generate
import { generate } from 'ros-typescript-generator'
While primarily a CLI tool, a core `generate` function may be exposed for programmatic use in build scripts or custom tooling, allowing direct invocation with a configuration object.
CliConfig
import { CliConfig } from 'ros-typescript-generator'
Type definition for the configuration object used by the CLI tool, useful if constructing configuration programmatically or for type-checking custom CLI wrappers.
RosVersion
import { RosVersion } from 'ros-typescript-generator'
An exported enum or type representing the supported ROS versions (1 or 2), potentially useful for programmatic validation or configuration.

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);
ros-typescript-generator --version
Debug
Known issues
breakingVersion 1.8.0 introduced a change where service messages are bundled into a single message type containing distinct `Request` and `Response` sub-interfaces. This significantly alters the generated type structure for services.
fix
Existing code consuming generated service types from versions prior to 1.8.0 must be updated. For instance, `MyService` will now expose `MyService.Request` and `MyService.Response` for its respective components.
affects: >=1.8.0
gotchaIncorrect or inaccessible paths specified in the `input` array of your configuration file will cause the generation process to fail silently or with an error, as the CLI cannot locate the ROS message files.
fix
Carefully verify that all `path` entries in `ros-ts-generator-config.json` are correct absolute paths or paths relative to the config file, and that the CLI has necessary read permissions for these directories.
affects: >=1.0.0
gotchaThe `smartEnums` feature, introduced in v1.9.0, changes how constants within `.msg` files are interpreted. When enabled, it attempts to infer distinct enum types, which might lead to unexpected enum generations if your constant naming conventions are ambiguous.
fix
If the generated enums are not as expected, either disable `smartEnums` in your configuration (`"smartEnums": false`) or refine the constant definitions in your `.msg` files to be more distinct for better inference.
affects: >=1.9.0
gotchaThe `rosVersion` field in the `ros-ts-generator-config.json` is mandatory and must be explicitly set to either `1` or `2`. Omitting it or providing an invalid value will result in a generation error.
fix
Always ensure your configuration includes `"rosVersion": 1` or `"rosVersion": 2` to specify the target ROS environment.
affects: >=1.0.0
Errors
Common errors & fixes
Error: ENOENT: no such file or directory, stat '/opt/ros/iron/share/std_msgs'
The generator could not find one of the ROS package directories specified in the `input` array of your `ros-ts-generator-config.json`.
fix
Double-check the `path` values in your configuration file. Ensure they are correct, absolute paths to existing ROS share directories, and that you have read permissions.
Error: No config file found at specified path.
The `ros-typescript-generator` CLI was invoked but could not locate the configuration file at the path provided by the `--config` argument.
fix
Verify that the `ros-ts-generator-config.json` file exists at the specified location and that the `--config` flag includes the correct full path and filename, e.g., `npx ros-typescript-generator --config ./ros-ts-generator-config.json`.
Error: Invalid ROS version '0' specified in config. Must be 1 or 2.
The `rosVersion` property in your `ros-ts-generator-config.json` is set to an invalid value (e.g., `0`, `3`, or a string).
fix
Correct the `rosVersion` entry in your configuration file to either `1` for ROS1 or `2` for ROS2.
Upgrade
Version history
1.10.0latest on npm
Audit
Dependencies
@foxglove/rosmsgrequiredUsed internally by the CLI for parsing ROS message definition files during the generation process.
Agent activity
12 hits · last 30 days
node
10
Bingbot
1
OpenAI (training)
1
Resources