aspect-build / aspect-build/rules_ts

[Bug]: Add snakeToCamel option to ts_proto_library to control field naming convention

Open
#771 1 comment 0 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
Starlark
Stars
138
Forks
87
Avg merge
2d 8h
Merged PRs (30d)
3

Description

### What happened?

I am using ts_proto_library from rules_ts to generate TypeScript definitions from my .proto files. However, I noticed that fields defined in snake_case in the .proto files are automatically converted to camelCase in the generated .d.ts files.

For example, given this .proto definition:

```proto
message Example {
string example_field = 1;
}
```

The generated TypeScript definition is:

```ts
interface Example {
exampleField: string;
}
```

This automatic conversion is not always desirable, especially when working with APIs that expect snake_case field names.

Currently, rules_ts does not provide an option to disable this conversion. Many users of ts-proto rely on the snakeToCamel option (--ts_proto_opt=snakeToCamel=false) to keep the generated TypeScript field names consistent with their .proto definitions. However, ts_proto_library in rules_ts does not expose a way to pass this option.

### Version

Development (host) and target OS/architectures:

Output of `bazel --version`: aspect oss 2024.45.21-2252fc6 (with local changes)

Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file:

Language(s) and/or frameworks involved: TypeScript

### How to reproduce

```shell
1. Define a .proto file with snake_case field names.
2. Use ts_proto_library from rules_ts to generate TypeScript definitions.
3. Observe that the generated TypeScript uses camelCase instead of snake_case.
```

### Any other information?

Would it be possible to expose an option in ts_proto_library to control this behavior? Specifically, allowing users to pass --ts_proto_opt=snakeToCamel=false to protoc-gen-ts_proto would make it more flexible.

This feature would help teams that want to maintain consistency between .proto field names and the generated TypeScript types, avoiding unexpected naming mismatches.

Let me know if you need any additional details! Thanks for maintaining rules_ts! 🚀

Contributor guide

Open the contributing guide

Research direction

Start at the ts_proto_library rule and trace how it invokes protoc-gen-ts_proto. Check how rule options are exposed, then verify generation with a proto field such as example_field. Done means users can pass snakeToCamel=false and generated TypeScript preserves snake_case names.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.