-
I just started using protobuf-ts and I would like to say thank you so much for creating this. The quality of the ts generated is superb. I managed to migrate one of my calls from improbable to the code generated with the web transport. It transpiles ok. However, babel seems to get on the way. With the default babel preset, this code: class ChatStatusQueryRequest$Type extends MessageType<ChatStatusQueryRequest> {
constructor() {
super("support.v1.ChatStatusQueryRequest", []);
}
} is transformed into: var ChatStatusQueryRequest$Type = /*#__PURE__*/function (_MessageType) {
(0,_babel_runtime_helpers_esm_inheritsLoose__WEBPACK_IMPORTED_MODULE_0__["default"])(ChatStatusQueryRequest$Type, _MessageType);
function ChatStatusQueryRequest$Type() {
return _MessageType.call(this, "support.v1.ChatStatusQueryRequest", []) || this;
}
return ChatStatusQueryRequest$Type;
}(_protobuf_ts_runtime__WEBPACK_IMPORTED_MODULE_1__.MessageType); and it doesn't work. As soon as the I've managed to narrow it down to how babel interprets super calls here. This option in .babelrc seems to do the trick: "assumptions": {
"superIsCallableConstructor": false
}, And now it works!!! I just wanted to get some confirmation if this is the right approach. And if its, then I think a few lines to the manual somewhere would be very useful. I can do a PR if it's ok |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I have not used Babel for a long time. A class that calls it's super constructor does not seem very extraordinary, so I'm a bit surprised that extra configuration seems to be necessary. Babel's docs say:
So you should check whether your code base extends |
Beta Was this translation helpful? Give feedback.
-
In case anybody lands here, I now got to the bottom of what was happening here.
I had to change my webpack filter to include |
Beta Was this translation helpful? Give feedback.
-
I'm running into a similar issue on a pretty vanilla demo setup without any babel -- simply running
I have the target set to |
Beta Was this translation helpful? Give feedback.
In case anybody lands here, I now got to the bottom of what was happening here.
@protobuf-ts
packages are transpiled into ES6, and so classes are left alone as native classes. However, all the generated code from protobuf will extend those classes and webpack/babel will transpile this code. In a default setup, webpack won't pass@protobuf-ts
to Babel as node_modules are usually not transpiled again. This means that in my application code generated from protobuf schemas may (or may not) be transpiled to es5, and so a class will become a series of function calls. These functions will call theMessageType
constructor as the generated classes extend it. Yet, sinceMessageType
is a native clas…