protobuf.js version: 6.9.0
nodejs: 14.2.0
If I have class after enum in JS file (after pbjs command), I can't see interfaces for it in TS file after pbts command. But interfaces for classes before enum is in TS file and they work fine.
However if I change jsdoc from 3.6.4 to 3.5.5 version, all interface is generated fine.
Examle:
/**
* IntSize enum.
* @exports IntSize
* @enum {number}
* @property {number} IS_DEFAULT=0 IS_DEFAULT value
* @property {number} IS_8=8 IS_8 value
* @property {number} IS_16=16 IS_16 value
* @property {number} IS_32=32 IS_32 value
* @property {number} IS_64=64 IS_64 value
*/
$root.IntSize = (function() {
var valuesById = {}, values = Object.create(valuesById);
values[valuesById[0] = "IS_DEFAULT"] = 0;
values[valuesById[8] = "IS_8"] = 8;
values[valuesById[16] = "IS_16"] = 16;
values[valuesById[32] = "IS_32"] = 32;
values[valuesById[64] = "IS_64"] = 64;
return values;
})();
$root.NanoPBOptions = (function() {
/**
* Properties of a NanoPBOptions.
* @exports INanoPBOptions
* @interface INanoPBOptions
* @property {number|null} [maxSize] NanoPBOptions maxSize
* @property {number|null} [maxLength] NanoPBOptions maxLength
* @property {number|null} [maxCount] NanoPBOptions maxCount
* @property {IntSize|null} [intSize] NanoPBOptions intSize
* @property {FieldType|null} [type] NanoPBOptions type
* @property {boolean|null} [longNames] NanoPBOptions longNames
* @property {boolean|null} [packedStruct] NanoPBOptions packedStruct
* @property {boolean|null} [packedEnum] NanoPBOptions packedEnum
* @property {boolean|null} [skipMessage] NanoPBOptions skipMessage
* @property {boolean|null} [noUnions] NanoPBOptions noUnions
* @property {number|null} [msgid] NanoPBOptions msgid
* @property {boolean|null} [anonymousOneof] NanoPBOptions anonymousOneof
* @property {boolean|null} [proto3] NanoPBOptions proto3
* @property {boolean|null} [enumToString] NanoPBOptions enumToString
* @property {boolean|null} [fixedLength] NanoPBOptions fixedLength
* @property {boolean|null} [fixedCount] NanoPBOptions fixedCount
*/
I debug this. I seen list of Doclet objects in taffy().get() here: my_project/node_modules/protobufjs/cli/lib/tsd-jsdoc/publish.js
// JSDoc hook
exports.publish = function publish(taffy, opts) {
options = opts || {};
Many Doclet objects have field "memberof". Next in source code it field used for filtering of element list.
Whre I use jsdoc 3.5.5, Doclet for interface INanoPBOptions is memberof "undefined". So it is root element and interface will be created in TS.
Whre I use jsdoc 3.6.4, Doclet for interface INanoPBOptions is memberof "module:IntSize". It take it from enum? So it is not root element and interface will not be created in TS.
I am able to recreate this issue with my project.
Here's a short proto file to recreate:
syntax = "proto3";
message GoodMessage {
uint32 test_1 = 1;
}
enum BreakingEnum {
VALUE_1 = 0;
VALUE_2 = 1;
}
message BrokenMessage {
uint32 test_2 = 1;
}
Commands I ran to recreate:
yarn pbjs -t static-module -w commonjs -o test.js test.proto
yarn pbts -o test.d.ts test.js
In test.d.ts there is no definition for IBrokenMessage interface which the class BrokenMessage implements.
My current workaround is to move all file level enums to the bottom of my proto file.
Thanks for this (ugly) workaround!
I have found temporary solution how to fixed it.
Tested on: protobuf.js 6.10.2, nodejs 12.14.1 and nodejs 14.15.1 too.
Problem what I have solved:
1) pbts skips creating interfaces if jsdoc version in his dependencies is above 3.5.5. (See top of this topic).
2) If version of jsdoc is 3.5.5, then it works fine with older nodes, but then it does not work with nodejs 12 and 14.
Solution:
1) I forked jsdoc from 3.5.5 and add only one fix what fix problem with nodejs 12 and 14 compatibility. https://github.com/VitalyName/jsdoc/commit/80443ca629052fc7aa8ff83ad3331be3123e39ce
2) I forked protobuf.js and change source for jsdoc in his dependencies to commit from step one.
https://github.com/VitalyName/protobuf.js/commit/236a7c757a5eada7926fdff149d0b49ada838275
3) I added to package.json in my project new dev dependecies (commit from step 2)
"devDependencies": {
"protobufjs": "git://github.com/VitalyName/protobuf.js.git#236a7c757a5eada7926fdff149d0b49ada838275"
}
instead of
"devDependencies": {
"protobufjs": "6.10.2"
}
This is obviously, you need to use only step 3 to fix it
Most helpful comment
I am able to recreate this issue with my project.
Here's a short proto file to recreate:
Commands I ran to recreate:
yarn pbjs -t static-module -w commonjs -o test.js test.protoyarn pbts -o test.d.ts test.jsIn
test.d.tsthere is no definition for IBrokenMessage interface which the class BrokenMessage implements.My current workaround is to move all file level enums to the bottom of my proto file.