-
-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TS types] can we have camel casing for field names? #40
Comments
somehow I missed that haha, yeah I think we should use whatever is idiomatic for the target language, so SGTM, I'll fix that today |
370c365 thanks! |
oh actually I just remembered why it's this way, because TS will serialize the fields incorrectly. If fields are defined as |
Not sure what you mean here. Looked at the ts client code and this is what I understand is happening:
Yea I guess we can't do this within JSON.parse reviver but shouldn't it be straightforward to recurse on the object fields and create a new object with camel case? |
It's definitely doable to recurse, but I'm not sure it's really worth the pain, I don't mind the snake-case much personally but I don't use any linters. If there is a clean way to do it in TS I'm definitely cool with it, but keep in mind it has to work for regular JS as well as TS. I think we can maybe use the JSON.stringify/parse callbacks, looks like we'd have to return |
Played a bit with JSON.parse callback but couldn't get it to work on firefox:
I guess if you return undefined it just throws the whole thing away? Maybe I missed something. This seems a bit hacky anyways and I guess it would also depend on JSON.parse/stringify implementation in the engine so I wouldn't go for this approach. I'll do a PR so let's see how it can be implemented. |
Currently it's snake_cased: https://github.com/apex/rpc/blob/master/generators/tstypes/testdata/todo_types.ts#L4
I'm using prettier on my codebase which is a very opinionated code formatter and I guess many other people are too considering the number of stars it has on github.
Prettier is strict about using camelCasing for object field names so it gives me very annoying eslint errors when I try to instantiate api types.
It would be great if we had a flag in the generator to generate camelCased fields instead. WDYT?
The text was updated successfully, but these errors were encountered: