Proto2TypeScript icon indicating copy to clipboard operation
Proto2TypeScript copied to clipboard

Maps are not generated properly

Open michelgb opened this issue 9 years ago • 6 comments

Hello. I notice maps are not properly converted to typescript definitions. For example.

map<string, int32> attr1 = 1;

should convert to

attr1 { [key: string]: number }

michelgb avatar Feb 06 '16 13:02 michelgb

I need this too. Also seems "repeated" and "oneof" fields aren’t generated properly either. About to have a look at how difficult it’ll be to implement…

DouglasHeriot avatar Feb 11 '16 08:02 DouglasHeriot

It seems repeated fields are fine, but oneofs and maps are missing. These are both protobuf 3 features.

This is the first time I’ve ever used Dusty templates. I don’t fully see their value in this case – I’ve got to look at how to split the logic between the command.ts and the templates. I’m pretty tempted to just remove Dusty and put it all in Typescript.

DouglasHeriot avatar Feb 11 '16 12:02 DouglasHeriot

Hei, Yes I don't think I implemented oneofs and maps. You could remove the Dusty templates, if you think the code will be more beautiful without them. The idea was to avoid a lot of ugly string concatenations in the source code.

fungiboletus avatar Feb 11 '16 13:02 fungiboletus

Done, works for me. Not tested extensively with different types of keys.

I ended up keeping Dusty, once I found how to add simply if statements. Just not sure how much repetition it’ll lead to, if maps are implemented in get/set methods.

DouglasHeriot avatar Feb 12 '16 02:02 DouglasHeriot

Well, I should have looked earlier – there’s a fork that already has support for proto3 maps: https://github.com/michelgb/Proto2TypeScript/blob/master/templates/interface.dust

It’s very similar to my implementation, but more complete. Might need to have a look at it and consider merging it instead.

DouglasHeriot avatar Feb 12 '16 05:02 DouglasHeriot

This can be closed now that #8 is merged.

DouglasHeriot avatar Apr 27 '16 12:04 DouglasHeriot