A CLI for generating typescript interfaces and enums from ros msg
files.
- ROS1 and ROS2 support
- Generate ts types from ROS
msgs
- Generate ts enums from ROS
msgs
- Configurable type prefix, eg)
IRosType
orRos
- Works with custom
msgs
- No runtime dependencies
- Advanced multi-enum support
# example_msgs/example.msg
uint8 STATUS_DISABLED = 0
uint8 STATUS_ENABLED = 1
uint8 OTHER_THING_1 = 1
uint8 OTHER_THING_2 = 2
uint8 status
uint8 other
uint8 more
Should become:
export enum IRosTypeExampleStatus {
"STATUS_DISABLED" = 0,
"STATUS_ENABLED" = 1,
}
export enum IRosTypeExampleOther {
"OTHER_THING_1" = 1,
"OTHER_THING_2" = 2
}
export interface IRosTypeExampleOther {
status: IRosTypeExampleStatus
other: IRosTypeExampleOther
more: number
}
Unlike rostsd-gen, this ONLY generates ts types and enums. This means the output does not include any nodejs dependencies. In fact, it has no runtime dependencies at all. It uses interfaces rather than classes 🙂. This makes it good option for any frontend project.
- Add a
ros-ts-generator-config.json
file to your project root. For example:
{
"output": "./generated/ros_msgs.ts",
"rosVersion": 2, // 1 or 2
"input": [
{
"namespace": "std_msgs",
"path": "/opt/ros/galactic/share/std_msgs"
},
{
"namespace": "geometry_msgs",
"path": "/opt/ros/galactic/share/geometry_msgs"
},
// Add any other messages including your own custom messages.
],
"typePrefix": "IRosType"
}
- Run
npx ros-typescript-generator --config ros-ts-generator-config.json
- Done!
Credit goes to foxglove for their foxglove/rosmsg library.