protobufjs / protobuf.js

Protocol Buffers for JavaScript & TypeScript.
Other
9.85k stars 1.41k forks source link

Interface for a class is missing in typescript on linux/macos #1222

Open prudd42 opened 5 years ago

prudd42 commented 5 years ago

protobuf.js version: 6.6.8 nodejs version 11.6 yarn version 1.12 angular-cli version 7.3.6

When compiling our proto file on Linux or Mac the resulting typescript file is missing the needed interfaces for various classes. Yet when we run the same script on Windows (using 'git version 2.19.1.windows.1' as the shell on Windows) the interfaces are there as expected. This results in the ng build failing on Linux or Mac but succeeding on Windows.


Proto File ```proto syntax = "proto3"; option csharp_namespace = "ActiveFloor.Messages.Scores"; enum PlayerColor { RED = 0; BLUE = 1; GREEN = 2; YELLOW = 3; PURPLE = 4; } message PlayerScore { PlayerColor player = 1; sint32 score = 2; } message Scores { repeated PlayerScore scores = 1; } message HighScores { repeated sint32 highScores = 1; } ```
Compilation Script ```sh #!/bin/sh SOURCE_DIR="src/app/messages" BUILD_DIR="src/app/models" # Remove old build products [ -e $BUILD_DIR/ProtocolBufferMessages.js ] && rm $BUILD_DIR/ProtocolBufferMessages.js [ -e $BUILD_DIR/ProtocolBufferMessages.d.ts ] && rm $BUILD_DIR/ProtocolBufferMessages.d.ts # Make sure the directory where we will put the files exists. mkdir -p $BUILD_DIR # Compile the Protocol Buffer files. yarn run pbjs -t static-module -w commonjs -o $BUILD_DIR/ProtocolBufferMessages.js \ $SOURCE_DIR/ScoreMessages/ScoreMessages.proto \ yarn run pbts -o $BUILD_DIR/ProtocolBufferMessages.d.ts $BUILD_DIR/ProtocolBufferMessages.js ```
Intermediate JavaScript file on Linux or Mac ```js /*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/ "use strict"; var $protobuf = require("protobufjs/minimal"); // Common aliases var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; // Exported root namespace var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); /** * PlayerColor enum. * @exports PlayerColor * @enum {string} * @property {number} RED=0 RED value * @property {number} BLUE=1 BLUE value * @property {number} GREEN=2 GREEN value * @property {number} YELLOW=3 YELLOW value * @property {number} PURPLE=4 PURPLE value */ $root.PlayerColor = (function() { var valuesById = {}, values = Object.create(valuesById); values[valuesById[0] = "RED"] = 0; values[valuesById[1] = "BLUE"] = 1; values[valuesById[2] = "GREEN"] = 2; values[valuesById[3] = "YELLOW"] = 3; values[valuesById[4] = "PURPLE"] = 4; return values; })(); $root.PlayerScore = (function() { /** * Properties of a PlayerScore. * @exports IPlayerScore * @interface IPlayerScore * @property {PlayerColor|null} [player] PlayerScore player * @property {number|null} [score] PlayerScore score */ /** * Constructs a new PlayerScore. * @exports PlayerScore * @classdesc Represents a PlayerScore. * @implements IPlayerScore * @constructor * @param {IPlayerScore=} [properties] Properties to set */ function PlayerScore(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; } /** * PlayerScore player. * @member {PlayerColor} player * @memberof PlayerScore * @instance */ PlayerScore.prototype.player = 0; /** * PlayerScore score. * @member {number} score * @memberof PlayerScore * @instance */ PlayerScore.prototype.score = 0; /** * Creates a new PlayerScore instance using the specified properties. * @function create * @memberof PlayerScore * @static * @param {IPlayerScore=} [properties] Properties to set * @returns {PlayerScore} PlayerScore instance */ PlayerScore.create = function create(properties) { return new PlayerScore(properties); }; /** * Encodes the specified PlayerScore message. Does not implicitly {@link PlayerScore.verify|verify} messages. * @function encode * @memberof PlayerScore * @static * @param {IPlayerScore} message PlayerScore message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ PlayerScore.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); if (message.player != null && message.hasOwnProperty("player")) writer.uint32(/* id 1, wireType 0 =*/8).int32(message.player); if (message.score != null && message.hasOwnProperty("score")) writer.uint32(/* id 2, wireType 0 =*/16).sint32(message.score); return writer; }; /** * Encodes the specified PlayerScore message, length delimited. Does not implicitly {@link PlayerScore.verify|verify} messages. * @function encodeDelimited * @memberof PlayerScore * @static * @param {IPlayerScore} message PlayerScore message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ PlayerScore.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** * Decodes a PlayerScore message from the specified reader or buffer. * @function decode * @memberof PlayerScore * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand * @returns {PlayerScore} PlayerScore * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ PlayerScore.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); var end = length === undefined ? reader.len : reader.pos + length, message = new $root.PlayerScore(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: message.player = reader.int32(); break; case 2: message.score = reader.sint32(); break; default: reader.skipType(tag & 7); break; } } return message; }; /** * Decodes a PlayerScore message from the specified reader or buffer, length delimited. * @function decodeDelimited * @memberof PlayerScore * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @returns {PlayerScore} PlayerScore * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ PlayerScore.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** * Verifies a PlayerScore message. * @function verify * @memberof PlayerScore * @static * @param {Object.} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ PlayerScore.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; if (message.player != null && message.hasOwnProperty("player")) switch (message.player) { default: return "player: enum value expected"; case 0: case 1: case 2: case 3: case 4: break; } if (message.score != null && message.hasOwnProperty("score")) if (!$util.isInteger(message.score)) return "score: integer expected"; return null; }; /** * Creates a PlayerScore message from a plain object. Also converts values to their respective internal types. * @function fromObject * @memberof PlayerScore * @static * @param {Object.} object Plain object * @returns {PlayerScore} PlayerScore */ PlayerScore.fromObject = function fromObject(object) { if (object instanceof $root.PlayerScore) return object; var message = new $root.PlayerScore(); switch (object.player) { case "RED": case 0: message.player = 0; break; case "BLUE": case 1: message.player = 1; break; case "GREEN": case 2: message.player = 2; break; case "YELLOW": case 3: message.player = 3; break; case "PURPLE": case 4: message.player = 4; break; } if (object.score != null) message.score = object.score | 0; return message; }; /** * Creates a plain object from a PlayerScore message. Also converts values to other types if specified. * @function toObject * @memberof PlayerScore * @static * @param {PlayerScore} message PlayerScore * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ PlayerScore.toObject = function toObject(message, options) { if (!options) options = {}; var object = {}; if (options.defaults) { object.player = options.enums === String ? "RED" : 0; object.score = 0; } if (message.player != null && message.hasOwnProperty("player")) object.player = options.enums === String ? $root.PlayerColor[message.player] : message.player; if (message.score != null && message.hasOwnProperty("score")) object.score = message.score; return object; }; /** * Converts this PlayerScore to JSON. * @function toJSON * @memberof PlayerScore * @instance * @returns {Object.} JSON object */ PlayerScore.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; return PlayerScore; })(); $root.Scores = (function() { /** * Properties of a Scores. * @exports IScores * @interface IScores * @property {Array.|null} [scores] Scores scores */ /** * Constructs a new Scores. * @exports Scores * @classdesc Represents a Scores. * @implements IScores * @constructor * @param {IScores=} [properties] Properties to set */ function Scores(properties) { this.scores = []; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; } /** * Scores scores. * @member {Array.} scores * @memberof Scores * @instance */ Scores.prototype.scores = $util.emptyArray; /** * Creates a new Scores instance using the specified properties. * @function create * @memberof Scores * @static * @param {IScores=} [properties] Properties to set * @returns {Scores} Scores instance */ Scores.create = function create(properties) { return new Scores(properties); }; /** * Encodes the specified Scores message. Does not implicitly {@link Scores.verify|verify} messages. * @function encode * @memberof Scores * @static * @param {IScores} message Scores message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ Scores.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); if (message.scores != null && message.scores.length) for (var i = 0; i < message.scores.length; ++i) $root.PlayerScore.encode(message.scores[i], writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); return writer; }; /** * Encodes the specified Scores message, length delimited. Does not implicitly {@link Scores.verify|verify} messages. * @function encodeDelimited * @memberof Scores * @static * @param {IScores} message Scores message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ Scores.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** * Decodes a Scores message from the specified reader or buffer. * @function decode * @memberof Scores * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand * @returns {Scores} Scores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ Scores.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Scores(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: if (!(message.scores && message.scores.length)) message.scores = []; message.scores.push($root.PlayerScore.decode(reader, reader.uint32())); break; default: reader.skipType(tag & 7); break; } } return message; }; /** * Decodes a Scores message from the specified reader or buffer, length delimited. * @function decodeDelimited * @memberof Scores * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @returns {Scores} Scores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ Scores.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** * Verifies a Scores message. * @function verify * @memberof Scores * @static * @param {Object.} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ Scores.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; if (message.scores != null && message.hasOwnProperty("scores")) { if (!Array.isArray(message.scores)) return "scores: array expected"; for (var i = 0; i < message.scores.length; ++i) { var error = $root.PlayerScore.verify(message.scores[i]); if (error) return "scores." + error; } } return null; }; /** * Creates a Scores message from a plain object. Also converts values to their respective internal types. * @function fromObject * @memberof Scores * @static * @param {Object.} object Plain object * @returns {Scores} Scores */ Scores.fromObject = function fromObject(object) { if (object instanceof $root.Scores) return object; var message = new $root.Scores(); if (object.scores) { if (!Array.isArray(object.scores)) throw TypeError(".Scores.scores: array expected"); message.scores = []; for (var i = 0; i < object.scores.length; ++i) { if (typeof object.scores[i] !== "object") throw TypeError(".Scores.scores: object expected"); message.scores[i] = $root.PlayerScore.fromObject(object.scores[i]); } } return message; }; /** * Creates a plain object from a Scores message. Also converts values to other types if specified. * @function toObject * @memberof Scores * @static * @param {Scores} message Scores * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ Scores.toObject = function toObject(message, options) { if (!options) options = {}; var object = {}; if (options.arrays || options.defaults) object.scores = []; if (message.scores && message.scores.length) { object.scores = []; for (var j = 0; j < message.scores.length; ++j) object.scores[j] = $root.PlayerScore.toObject(message.scores[j], options); } return object; }; /** * Converts this Scores to JSON. * @function toJSON * @memberof Scores * @instance * @returns {Object.} JSON object */ Scores.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; return Scores; })(); $root.HighScores = (function() { /** * Properties of a HighScores. * @exports IHighScores * @interface IHighScores * @property {Array.|null} [highScores] HighScores highScores */ /** * Constructs a new HighScores. * @exports HighScores * @classdesc Represents a HighScores. * @implements IHighScores * @constructor * @param {IHighScores=} [properties] Properties to set */ function HighScores(properties) { this.highScores = []; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; } /** * HighScores highScores. * @member {Array.} highScores * @memberof HighScores * @instance */ HighScores.prototype.highScores = $util.emptyArray; /** * Creates a new HighScores instance using the specified properties. * @function create * @memberof HighScores * @static * @param {IHighScores=} [properties] Properties to set * @returns {HighScores} HighScores instance */ HighScores.create = function create(properties) { return new HighScores(properties); }; /** * Encodes the specified HighScores message. Does not implicitly {@link HighScores.verify|verify} messages. * @function encode * @memberof HighScores * @static * @param {IHighScores} message HighScores message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ HighScores.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); if (message.highScores != null && message.highScores.length) { writer.uint32(/* id 1, wireType 2 =*/10).fork(); for (var i = 0; i < message.highScores.length; ++i) writer.sint32(message.highScores[i]); writer.ldelim(); } return writer; }; /** * Encodes the specified HighScores message, length delimited. Does not implicitly {@link HighScores.verify|verify} messages. * @function encodeDelimited * @memberof HighScores * @static * @param {IHighScores} message HighScores message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ HighScores.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** * Decodes a HighScores message from the specified reader or buffer. * @function decode * @memberof HighScores * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand * @returns {HighScores} HighScores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ HighScores.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); var end = length === undefined ? reader.len : reader.pos + length, message = new $root.HighScores(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: if (!(message.highScores && message.highScores.length)) message.highScores = []; if ((tag & 7) === 2) { var end2 = reader.uint32() + reader.pos; while (reader.pos < end2) message.highScores.push(reader.sint32()); } else message.highScores.push(reader.sint32()); break; default: reader.skipType(tag & 7); break; } } return message; }; /** * Decodes a HighScores message from the specified reader or buffer, length delimited. * @function decodeDelimited * @memberof HighScores * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @returns {HighScores} HighScores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ HighScores.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** * Verifies a HighScores message. * @function verify * @memberof HighScores * @static * @param {Object.} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ HighScores.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; if (message.highScores != null && message.hasOwnProperty("highScores")) { if (!Array.isArray(message.highScores)) return "highScores: array expected"; for (var i = 0; i < message.highScores.length; ++i) if (!$util.isInteger(message.highScores[i])) return "highScores: integer[] expected"; } return null; }; /** * Creates a HighScores message from a plain object. Also converts values to their respective internal types. * @function fromObject * @memberof HighScores * @static * @param {Object.} object Plain object * @returns {HighScores} HighScores */ HighScores.fromObject = function fromObject(object) { if (object instanceof $root.HighScores) return object; var message = new $root.HighScores(); if (object.highScores) { if (!Array.isArray(object.highScores)) throw TypeError(".HighScores.highScores: array expected"); message.highScores = []; for (var i = 0; i < object.highScores.length; ++i) message.highScores[i] = object.highScores[i] | 0; } return message; }; /** * Creates a plain object from a HighScores message. Also converts values to other types if specified. * @function toObject * @memberof HighScores * @static * @param {HighScores} message HighScores * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ HighScores.toObject = function toObject(message, options) { if (!options) options = {}; var object = {}; if (options.arrays || options.defaults) object.highScores = []; if (message.highScores && message.highScores.length) { object.highScores = []; for (var j = 0; j < message.highScores.length; ++j) object.highScores[j] = message.highScores[j]; } return object; }; /** * Converts this HighScores to JSON. * @function toJSON * @memberof HighScores * @instance * @returns {Object.} JSON object */ HighScores.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; return HighScores; })(); module.exports = $root; ```
Resulting TypeScript file on Linux or Mac ```ts import * as $protobuf from "protobufjs"; /** PlayerColor enum. */ namespace PlayerColor { /** RED value */ let RED: number; /** BLUE value */ let BLUE: number; /** GREEN value */ let GREEN: number; /** YELLOW value */ let YELLOW: number; /** PURPLE value */ let PURPLE: number; } /** Represents a PlayerScore. */ export class PlayerScore implements IPlayerScore { /** * Constructs a new PlayerScore. * @param [properties] Properties to set */ constructor(properties?: IPlayerScore); /** PlayerScore player. */ public player: PlayerColor; /** PlayerScore score. */ public score: number; /** * Creates a new PlayerScore instance using the specified properties. * @param [properties] Properties to set * @returns PlayerScore instance */ public static create(properties?: IPlayerScore): PlayerScore; /** * Encodes the specified PlayerScore message. Does not implicitly {@link PlayerScore.verify|verify} messages. * @param message PlayerScore message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ public static encode(message: IPlayerScore, writer?: $protobuf.Writer): $protobuf.Writer; /** * Encodes the specified PlayerScore message, length delimited. Does not implicitly {@link PlayerScore.verify|verify} messages. * @param message PlayerScore message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ public static encodeDelimited(message: IPlayerScore, writer?: $protobuf.Writer): $protobuf.Writer; /** * Decodes a PlayerScore message from the specified reader or buffer. * @param reader Reader or buffer to decode from * @param [length] Message length if known beforehand * @returns PlayerScore * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): PlayerScore; /** * Decodes a PlayerScore message from the specified reader or buffer, length delimited. * @param reader Reader or buffer to decode from * @returns PlayerScore * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): PlayerScore; /** * Verifies a PlayerScore message. * @param message Plain object to verify * @returns `null` if valid, otherwise the reason why it is not */ public static verify(message: { [k: string]: any }): (string|null); /** * Creates a PlayerScore message from a plain object. Also converts values to their respective internal types. * @param object Plain object * @returns PlayerScore */ public static fromObject(object: { [k: string]: any }): PlayerScore; /** * Creates a plain object from a PlayerScore message. Also converts values to other types if specified. * @param message PlayerScore * @param [options] Conversion options * @returns Plain object */ public static toObject(message: PlayerScore, options?: $protobuf.IConversionOptions): { [k: string]: any }; /** * Converts this PlayerScore to JSON. * @returns JSON object */ public toJSON(): { [k: string]: any }; } /** Represents a Scores. */ export class Scores implements IScores { /** * Constructs a new Scores. * @param [properties] Properties to set */ constructor(properties?: IScores); /** Scores scores. */ public scores: IPlayerScore[]; /** * Creates a new Scores instance using the specified properties. * @param [properties] Properties to set * @returns Scores instance */ public static create(properties?: IScores): Scores; /** * Encodes the specified Scores message. Does not implicitly {@link Scores.verify|verify} messages. * @param message Scores message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ public static encode(message: IScores, writer?: $protobuf.Writer): $protobuf.Writer; /** * Encodes the specified Scores message, length delimited. Does not implicitly {@link Scores.verify|verify} messages. * @param message Scores message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ public static encodeDelimited(message: IScores, writer?: $protobuf.Writer): $protobuf.Writer; /** * Decodes a Scores message from the specified reader or buffer. * @param reader Reader or buffer to decode from * @param [length] Message length if known beforehand * @returns Scores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Scores; /** * Decodes a Scores message from the specified reader or buffer, length delimited. * @param reader Reader or buffer to decode from * @returns Scores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Scores; /** * Verifies a Scores message. * @param message Plain object to verify * @returns `null` if valid, otherwise the reason why it is not */ public static verify(message: { [k: string]: any }): (string|null); /** * Creates a Scores message from a plain object. Also converts values to their respective internal types. * @param object Plain object * @returns Scores */ public static fromObject(object: { [k: string]: any }): Scores; /** * Creates a plain object from a Scores message. Also converts values to other types if specified. * @param message Scores * @param [options] Conversion options * @returns Plain object */ public static toObject(message: Scores, options?: $protobuf.IConversionOptions): { [k: string]: any }; /** * Converts this Scores to JSON. * @returns JSON object */ public toJSON(): { [k: string]: any }; } /** Represents a HighScores. */ export class HighScores implements IHighScores { /** * Constructs a new HighScores. * @param [properties] Properties to set */ constructor(properties?: IHighScores); /** HighScores highScores. */ public highScores: number[]; /** * Creates a new HighScores instance using the specified properties. * @param [properties] Properties to set * @returns HighScores instance */ public static create(properties?: IHighScores): HighScores; /** * Encodes the specified HighScores message. Does not implicitly {@link HighScores.verify|verify} messages. * @param message HighScores message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ public static encode(message: IHighScores, writer?: $protobuf.Writer): $protobuf.Writer; /** * Encodes the specified HighScores message, length delimited. Does not implicitly {@link HighScores.verify|verify} messages. * @param message HighScores message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ public static encodeDelimited(message: IHighScores, writer?: $protobuf.Writer): $protobuf.Writer; /** * Decodes a HighScores message from the specified reader or buffer. * @param reader Reader or buffer to decode from * @param [length] Message length if known beforehand * @returns HighScores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): HighScores; /** * Decodes a HighScores message from the specified reader or buffer, length delimited. * @param reader Reader or buffer to decode from * @returns HighScores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): HighScores; /** * Verifies a HighScores message. * @param message Plain object to verify * @returns `null` if valid, otherwise the reason why it is not */ public static verify(message: { [k: string]: any }): (string|null); /** * Creates a HighScores message from a plain object. Also converts values to their respective internal types. * @param object Plain object * @returns HighScores */ public static fromObject(object: { [k: string]: any }): HighScores; /** * Creates a plain object from a HighScores message. Also converts values to other types if specified. * @param message HighScores * @param [options] Conversion options * @returns Plain object */ public static toObject(message: HighScores, options?: $protobuf.IConversionOptions): { [k: string]: any }; /** * Converts this HighScores to JSON. * @returns JSON object */ public toJSON(): { [k: string]: any }; } ```
Intermediate JavaScript file on Windows ```js /*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/ "use strict"; var $protobuf = require("protobufjs/minimal"); // Common aliases var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; // Exported root namespace var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); /** * PlayerColor enum. * @exports PlayerColor * @enum {string} * @property {number} RED=0 RED value * @property {number} BLUE=1 BLUE value * @property {number} GREEN=2 GREEN value * @property {number} YELLOW=3 YELLOW value * @property {number} PURPLE=4 PURPLE value */ $root.PlayerColor = (function() { var valuesById = {}, values = Object.create(valuesById); values[valuesById[0] = "RED"] = 0; values[valuesById[1] = "BLUE"] = 1; values[valuesById[2] = "GREEN"] = 2; values[valuesById[3] = "YELLOW"] = 3; values[valuesById[4] = "PURPLE"] = 4; return values; })(); $root.PlayerScore = (function() { /** * Properties of a PlayerScore. * @exports IPlayerScore * @interface IPlayerScore * @property {PlayerColor|null} [player] PlayerScore player * @property {number|null} [score] PlayerScore score */ /** * Constructs a new PlayerScore. * @exports PlayerScore * @classdesc Represents a PlayerScore. * @implements IPlayerScore * @constructor * @param {IPlayerScore=} [properties] Properties to set */ function PlayerScore(properties) { if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; } /** * PlayerScore player. * @member {PlayerColor} player * @memberof PlayerScore * @instance */ PlayerScore.prototype.player = 0; /** * PlayerScore score. * @member {number} score * @memberof PlayerScore * @instance */ PlayerScore.prototype.score = 0; /** * Creates a new PlayerScore instance using the specified properties. * @function create * @memberof PlayerScore * @static * @param {IPlayerScore=} [properties] Properties to set * @returns {PlayerScore} PlayerScore instance */ PlayerScore.create = function create(properties) { return new PlayerScore(properties); }; /** * Encodes the specified PlayerScore message. Does not implicitly {@link PlayerScore.verify|verify} messages. * @function encode * @memberof PlayerScore * @static * @param {IPlayerScore} message PlayerScore message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ PlayerScore.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); if (message.player != null && message.hasOwnProperty("player")) writer.uint32(/* id 1, wireType 0 =*/8).int32(message.player); if (message.score != null && message.hasOwnProperty("score")) writer.uint32(/* id 2, wireType 0 =*/16).sint32(message.score); return writer; }; /** * Encodes the specified PlayerScore message, length delimited. Does not implicitly {@link PlayerScore.verify|verify} messages. * @function encodeDelimited * @memberof PlayerScore * @static * @param {IPlayerScore} message PlayerScore message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ PlayerScore.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** * Decodes a PlayerScore message from the specified reader or buffer. * @function decode * @memberof PlayerScore * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand * @returns {PlayerScore} PlayerScore * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ PlayerScore.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); var end = length === undefined ? reader.len : reader.pos + length, message = new $root.PlayerScore(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: message.player = reader.int32(); break; case 2: message.score = reader.sint32(); break; default: reader.skipType(tag & 7); break; } } return message; }; /** * Decodes a PlayerScore message from the specified reader or buffer, length delimited. * @function decodeDelimited * @memberof PlayerScore * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @returns {PlayerScore} PlayerScore * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ PlayerScore.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** * Verifies a PlayerScore message. * @function verify * @memberof PlayerScore * @static * @param {Object.} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ PlayerScore.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; if (message.player != null && message.hasOwnProperty("player")) switch (message.player) { default: return "player: enum value expected"; case 0: case 1: case 2: case 3: case 4: break; } if (message.score != null && message.hasOwnProperty("score")) if (!$util.isInteger(message.score)) return "score: integer expected"; return null; }; /** * Creates a PlayerScore message from a plain object. Also converts values to their respective internal types. * @function fromObject * @memberof PlayerScore * @static * @param {Object.} object Plain object * @returns {PlayerScore} PlayerScore */ PlayerScore.fromObject = function fromObject(object) { if (object instanceof $root.PlayerScore) return object; var message = new $root.PlayerScore(); switch (object.player) { case "RED": case 0: message.player = 0; break; case "BLUE": case 1: message.player = 1; break; case "GREEN": case 2: message.player = 2; break; case "YELLOW": case 3: message.player = 3; break; case "PURPLE": case 4: message.player = 4; break; } if (object.score != null) message.score = object.score | 0; return message; }; /** * Creates a plain object from a PlayerScore message. Also converts values to other types if specified. * @function toObject * @memberof PlayerScore * @static * @param {PlayerScore} message PlayerScore * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ PlayerScore.toObject = function toObject(message, options) { if (!options) options = {}; var object = {}; if (options.defaults) { object.player = options.enums === String ? "RED" : 0; object.score = 0; } if (message.player != null && message.hasOwnProperty("player")) object.player = options.enums === String ? $root.PlayerColor[message.player] : message.player; if (message.score != null && message.hasOwnProperty("score")) object.score = message.score; return object; }; /** * Converts this PlayerScore to JSON. * @function toJSON * @memberof PlayerScore * @instance * @returns {Object.} JSON object */ PlayerScore.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; return PlayerScore; })(); $root.Scores = (function() { /** * Properties of a Scores. * @exports IScores * @interface IScores * @property {Array.|null} [scores] Scores scores */ /** * Constructs a new Scores. * @exports Scores * @classdesc Represents a Scores. * @implements IScores * @constructor * @param {IScores=} [properties] Properties to set */ function Scores(properties) { this.scores = []; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; } /** * Scores scores. * @member {Array.} scores * @memberof Scores * @instance */ Scores.prototype.scores = $util.emptyArray; /** * Creates a new Scores instance using the specified properties. * @function create * @memberof Scores * @static * @param {IScores=} [properties] Properties to set * @returns {Scores} Scores instance */ Scores.create = function create(properties) { return new Scores(properties); }; /** * Encodes the specified Scores message. Does not implicitly {@link Scores.verify|verify} messages. * @function encode * @memberof Scores * @static * @param {IScores} message Scores message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ Scores.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); if (message.scores != null && message.scores.length) for (var i = 0; i < message.scores.length; ++i) $root.PlayerScore.encode(message.scores[i], writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); return writer; }; /** * Encodes the specified Scores message, length delimited. Does not implicitly {@link Scores.verify|verify} messages. * @function encodeDelimited * @memberof Scores * @static * @param {IScores} message Scores message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ Scores.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** * Decodes a Scores message from the specified reader or buffer. * @function decode * @memberof Scores * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand * @returns {Scores} Scores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ Scores.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Scores(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: if (!(message.scores && message.scores.length)) message.scores = []; message.scores.push($root.PlayerScore.decode(reader, reader.uint32())); break; default: reader.skipType(tag & 7); break; } } return message; }; /** * Decodes a Scores message from the specified reader or buffer, length delimited. * @function decodeDelimited * @memberof Scores * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @returns {Scores} Scores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ Scores.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** * Verifies a Scores message. * @function verify * @memberof Scores * @static * @param {Object.} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ Scores.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; if (message.scores != null && message.hasOwnProperty("scores")) { if (!Array.isArray(message.scores)) return "scores: array expected"; for (var i = 0; i < message.scores.length; ++i) { var error = $root.PlayerScore.verify(message.scores[i]); if (error) return "scores." + error; } } return null; }; /** * Creates a Scores message from a plain object. Also converts values to their respective internal types. * @function fromObject * @memberof Scores * @static * @param {Object.} object Plain object * @returns {Scores} Scores */ Scores.fromObject = function fromObject(object) { if (object instanceof $root.Scores) return object; var message = new $root.Scores(); if (object.scores) { if (!Array.isArray(object.scores)) throw TypeError(".Scores.scores: array expected"); message.scores = []; for (var i = 0; i < object.scores.length; ++i) { if (typeof object.scores[i] !== "object") throw TypeError(".Scores.scores: object expected"); message.scores[i] = $root.PlayerScore.fromObject(object.scores[i]); } } return message; }; /** * Creates a plain object from a Scores message. Also converts values to other types if specified. * @function toObject * @memberof Scores * @static * @param {Scores} message Scores * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ Scores.toObject = function toObject(message, options) { if (!options) options = {}; var object = {}; if (options.arrays || options.defaults) object.scores = []; if (message.scores && message.scores.length) { object.scores = []; for (var j = 0; j < message.scores.length; ++j) object.scores[j] = $root.PlayerScore.toObject(message.scores[j], options); } return object; }; /** * Converts this Scores to JSON. * @function toJSON * @memberof Scores * @instance * @returns {Object.} JSON object */ Scores.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; return Scores; })(); $root.HighScores = (function() { /** * Properties of a HighScores. * @exports IHighScores * @interface IHighScores * @property {Array.|null} [highScores] HighScores highScores */ /** * Constructs a new HighScores. * @exports HighScores * @classdesc Represents a HighScores. * @implements IHighScores * @constructor * @param {IHighScores=} [properties] Properties to set */ function HighScores(properties) { this.highScores = []; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]]; } /** * HighScores highScores. * @member {Array.} highScores * @memberof HighScores * @instance */ HighScores.prototype.highScores = $util.emptyArray; /** * Creates a new HighScores instance using the specified properties. * @function create * @memberof HighScores * @static * @param {IHighScores=} [properties] Properties to set * @returns {HighScores} HighScores instance */ HighScores.create = function create(properties) { return new HighScores(properties); }; /** * Encodes the specified HighScores message. Does not implicitly {@link HighScores.verify|verify} messages. * @function encode * @memberof HighScores * @static * @param {IHighScores} message HighScores message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ HighScores.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); if (message.highScores != null && message.highScores.length) { writer.uint32(/* id 1, wireType 2 =*/10).fork(); for (var i = 0; i < message.highScores.length; ++i) writer.sint32(message.highScores[i]); writer.ldelim(); } return writer; }; /** * Encodes the specified HighScores message, length delimited. Does not implicitly {@link HighScores.verify|verify} messages. * @function encodeDelimited * @memberof HighScores * @static * @param {IHighScores} message HighScores message or plain object to encode * @param {$protobuf.Writer} [writer] Writer to encode to * @returns {$protobuf.Writer} Writer */ HighScores.encodeDelimited = function encodeDelimited(message, writer) { return this.encode(message, writer).ldelim(); }; /** * Decodes a HighScores message from the specified reader or buffer. * @function decode * @memberof HighScores * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @param {number} [length] Message length if known beforehand * @returns {HighScores} HighScores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ HighScores.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); var end = length === undefined ? reader.len : reader.pos + length, message = new $root.HighScores(); while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { case 1: if (!(message.highScores && message.highScores.length)) message.highScores = []; if ((tag & 7) === 2) { var end2 = reader.uint32() + reader.pos; while (reader.pos < end2) message.highScores.push(reader.sint32()); } else message.highScores.push(reader.sint32()); break; default: reader.skipType(tag & 7); break; } } return message; }; /** * Decodes a HighScores message from the specified reader or buffer, length delimited. * @function decodeDelimited * @memberof HighScores * @static * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from * @returns {HighScores} HighScores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ HighScores.decodeDelimited = function decodeDelimited(reader) { if (!(reader instanceof $Reader)) reader = new $Reader(reader); return this.decode(reader, reader.uint32()); }; /** * Verifies a HighScores message. * @function verify * @memberof HighScores * @static * @param {Object.} message Plain object to verify * @returns {string|null} `null` if valid, otherwise the reason why it is not */ HighScores.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; if (message.highScores != null && message.hasOwnProperty("highScores")) { if (!Array.isArray(message.highScores)) return "highScores: array expected"; for (var i = 0; i < message.highScores.length; ++i) if (!$util.isInteger(message.highScores[i])) return "highScores: integer[] expected"; } return null; }; /** * Creates a HighScores message from a plain object. Also converts values to their respective internal types. * @function fromObject * @memberof HighScores * @static * @param {Object.} object Plain object * @returns {HighScores} HighScores */ HighScores.fromObject = function fromObject(object) { if (object instanceof $root.HighScores) return object; var message = new $root.HighScores(); if (object.highScores) { if (!Array.isArray(object.highScores)) throw TypeError(".HighScores.highScores: array expected"); message.highScores = []; for (var i = 0; i < object.highScores.length; ++i) message.highScores[i] = object.highScores[i] | 0; } return message; }; /** * Creates a plain object from a HighScores message. Also converts values to other types if specified. * @function toObject * @memberof HighScores * @static * @param {HighScores} message HighScores * @param {$protobuf.IConversionOptions} [options] Conversion options * @returns {Object.} Plain object */ HighScores.toObject = function toObject(message, options) { if (!options) options = {}; var object = {}; if (options.arrays || options.defaults) object.highScores = []; if (message.highScores && message.highScores.length) { object.highScores = []; for (var j = 0; j < message.highScores.length; ++j) object.highScores[j] = message.highScores[j]; } return object; }; /** * Converts this HighScores to JSON. * @function toJSON * @memberof HighScores * @instance * @returns {Object.} JSON object */ HighScores.prototype.toJSON = function toJSON() { return this.constructor.toObject(this, $protobuf.util.toJSONOptions); }; return HighScores; })(); module.exports = $root; ```
Resulting TypeScript on Windows ```ts import * as $protobuf from "protobufjs"; /** PlayerColor enum. */ export enum PlayerColor { RED = 0, BLUE = 1, GREEN = 2, YELLOW = 3, PURPLE = 4 } /** Properties of a PlayerScore. */ export interface IPlayerScore { /** PlayerScore player */ player?: (PlayerColor|null); /** PlayerScore score */ score?: (number|null); } /** Represents a PlayerScore. */ export class PlayerScore implements IPlayerScore { /** * Constructs a new PlayerScore. * @param [properties] Properties to set */ constructor(properties?: IPlayerScore); /** PlayerScore player. */ public player: PlayerColor; /** PlayerScore score. */ public score: number; /** * Creates a new PlayerScore instance using the specified properties. * @param [properties] Properties to set * @returns PlayerScore instance */ public static create(properties?: IPlayerScore): PlayerScore; /** * Encodes the specified PlayerScore message. Does not implicitly {@link PlayerScore.verify|verify} messages. * @param message PlayerScore message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ public static encode(message: IPlayerScore, writer?: $protobuf.Writer): $protobuf.Writer; /** * Encodes the specified PlayerScore message, length delimited. Does not implicitly {@link PlayerScore.verify|verify} messages. * @param message PlayerScore message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ public static encodeDelimited(message: IPlayerScore, writer?: $protobuf.Writer): $protobuf.Writer; /** * Decodes a PlayerScore message from the specified reader or buffer. * @param reader Reader or buffer to decode from * @param [length] Message length if known beforehand * @returns PlayerScore * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): PlayerScore; /** * Decodes a PlayerScore message from the specified reader or buffer, length delimited. * @param reader Reader or buffer to decode from * @returns PlayerScore * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): PlayerScore; /** * Verifies a PlayerScore message. * @param message Plain object to verify * @returns `null` if valid, otherwise the reason why it is not */ public static verify(message: { [k: string]: any }): (string|null); /** * Creates a PlayerScore message from a plain object. Also converts values to their respective internal types. * @param object Plain object * @returns PlayerScore */ public static fromObject(object: { [k: string]: any }): PlayerScore; /** * Creates a plain object from a PlayerScore message. Also converts values to other types if specified. * @param message PlayerScore * @param [options] Conversion options * @returns Plain object */ public static toObject(message: PlayerScore, options?: $protobuf.IConversionOptions): { [k: string]: any }; /** * Converts this PlayerScore to JSON. * @returns JSON object */ public toJSON(): { [k: string]: any }; } /** Properties of a Scores. */ export interface IScores { /** Scores scores */ scores?: (IPlayerScore[]|null); } /** Represents a Scores. */ export class Scores implements IScores { /** * Constructs a new Scores. * @param [properties] Properties to set */ constructor(properties?: IScores); /** Scores scores. */ public scores: IPlayerScore[]; /** * Creates a new Scores instance using the specified properties. * @param [properties] Properties to set * @returns Scores instance */ public static create(properties?: IScores): Scores; /** * Encodes the specified Scores message. Does not implicitly {@link Scores.verify|verify} messages. * @param message Scores message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ public static encode(message: IScores, writer?: $protobuf.Writer): $protobuf.Writer; /** * Encodes the specified Scores message, length delimited. Does not implicitly {@link Scores.verify|verify} messages. * @param message Scores message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ public static encodeDelimited(message: IScores, writer?: $protobuf.Writer): $protobuf.Writer; /** * Decodes a Scores message from the specified reader or buffer. * @param reader Reader or buffer to decode from * @param [length] Message length if known beforehand * @returns Scores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): Scores; /** * Decodes a Scores message from the specified reader or buffer, length delimited. * @param reader Reader or buffer to decode from * @returns Scores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): Scores; /** * Verifies a Scores message. * @param message Plain object to verify * @returns `null` if valid, otherwise the reason why it is not */ public static verify(message: { [k: string]: any }): (string|null); /** * Creates a Scores message from a plain object. Also converts values to their respective internal types. * @param object Plain object * @returns Scores */ public static fromObject(object: { [k: string]: any }): Scores; /** * Creates a plain object from a Scores message. Also converts values to other types if specified. * @param message Scores * @param [options] Conversion options * @returns Plain object */ public static toObject(message: Scores, options?: $protobuf.IConversionOptions): { [k: string]: any }; /** * Converts this Scores to JSON. * @returns JSON object */ public toJSON(): { [k: string]: any }; } /** Properties of a HighScores. */ export interface IHighScores { /** HighScores highScores */ highScores?: (number[]|null); } /** Represents a HighScores. */ export class HighScores implements IHighScores { /** * Constructs a new HighScores. * @param [properties] Properties to set */ constructor(properties?: IHighScores); /** HighScores highScores. */ public highScores: number[]; /** * Creates a new HighScores instance using the specified properties. * @param [properties] Properties to set * @returns HighScores instance */ public static create(properties?: IHighScores): HighScores; /** * Encodes the specified HighScores message. Does not implicitly {@link HighScores.verify|verify} messages. * @param message HighScores message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ public static encode(message: IHighScores, writer?: $protobuf.Writer): $protobuf.Writer; /** * Encodes the specified HighScores message, length delimited. Does not implicitly {@link HighScores.verify|verify} messages. * @param message HighScores message or plain object to encode * @param [writer] Writer to encode to * @returns Writer */ public static encodeDelimited(message: IHighScores, writer?: $protobuf.Writer): $protobuf.Writer; /** * Decodes a HighScores message from the specified reader or buffer. * @param reader Reader or buffer to decode from * @param [length] Message length if known beforehand * @returns HighScores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): HighScores; /** * Decodes a HighScores message from the specified reader or buffer, length delimited. * @param reader Reader or buffer to decode from * @returns HighScores * @throws {Error} If the payload is not a reader or valid buffer * @throws {$protobuf.util.ProtocolError} If required fields are missing */ public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): HighScores; /** * Verifies a HighScores message. * @param message Plain object to verify * @returns `null` if valid, otherwise the reason why it is not */ public static verify(message: { [k: string]: any }): (string|null); /** * Creates a HighScores message from a plain object. Also converts values to their respective internal types. * @param object Plain object * @returns HighScores */ public static fromObject(object: { [k: string]: any }): HighScores; /** * Creates a plain object from a HighScores message. Also converts values to other types if specified. * @param message HighScores * @param [options] Conversion options * @returns Plain object */ public static toObject(message: HighScores, options?: $protobuf.IConversionOptions): { [k: string]: any }; /** * Converts this HighScores to JSON. * @returns JSON object */ public toJSON(): { [k: string]: any }; } ```

Finally, when we go to build the whole project (with some other proto files that aren't included) we get the following stack trace.

Stack Trace ``` $ yarn build --prod yarn run v1.12.3 $ ng build --prod Date: 2019-05-14T20:22:15.277Z Hash: 793dc4cf2c64f07a592f Time: 13801ms chunk {0} runtime.26209474bfa8dc87a77c.js (runtime) 1.41 kB [entry] [rendered] chunk {1} es2015-polyfills.1e04665e16f944715fd2.js (es2015-polyfills) 56.4 kB [initial] [rendered] chunk {2} main.fa4681da67b0e16d34dc.js (main) 128 bytes [initial] [rendered] chunk {3} polyfills.41559ea504b9f00b6dea.js (polyfills) 130 bytes [initial] [rendered] chunk {4} styles.0fe1b01975df52cb54b0.css (styles) 150 kB [initial] [rendered] ERROR in src/app/models/ProtocolBufferMessages.d.ts(21,19): error TS2304: Cannot find name 'IHighScores'. src/app/models/ProtocolBufferMessages.d.ts(49,26): error TS2304: Cannot find name 'IHighScores'. src/app/models/ProtocolBufferMessages.d.ts(129,15): error TS2709: Cannot use namespace 'PlayerColor' as a type. src/app/models/ProtocolBufferMessages.d.ts(132,20): error TS2304: Cannot find name 'IScores'. src/app/models/ProtocolBufferMessages.d.ts(135,19): error TS2304: Cannot find name 'IHighScores'. src/app/models/ProtocolBufferMessages.d.ts(151,20): error TS2709: Cannot use namespace 'PlayerColor' as a type. src/app/models/ProtocolBufferMessages.d.ts(154,27): error TS2304: Cannot find name 'IScores'. src/app/models/ProtocolBufferMessages.d.ts(157,26): error TS2304: Cannot find name 'IHighScores'. src/app/models/ProtocolBufferMessages.d.ts(355,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. src/app/models/ProtocolBufferMessages.d.ts(374,37): error TS2304: Cannot find name 'IPlayerScore'. src/app/models/ProtocolBufferMessages.d.ts(380,30): error TS2304: Cannot find name 'IPlayerScore'. src/app/models/ProtocolBufferMessages.d.ts(383,20): error TS2709: Cannot use namespace 'PlayerColor' as a type. src/app/models/ProtocolBufferMessages.d.ts(393,39): error TS2304: Cannot find name 'IPlayerScore'. src/app/models/ProtocolBufferMessages.d.ts(401,35): error TS2304: Cannot find name 'IPlayerScore'. src/app/models/ProtocolBufferMessages.d.ts(409,44): error TS2304: Cannot find name 'IPlayerScore'. src/app/models/ProtocolBufferMessages.d.ts(460,32): error TS2304: Cannot find name 'IScores'. src/app/models/ProtocolBufferMessages.d.ts(466,30): error TS2304: Cannot find name 'IScores'. src/app/models/ProtocolBufferMessages.d.ts(469,20): error TS2304: Cannot find name 'IPlayerScore'. src/app/models/ProtocolBufferMessages.d.ts(476,39): error TS2304: Cannot find name 'IScores'. src/app/models/ProtocolBufferMessages.d.ts(484,35): error TS2304: Cannot find name 'IScores'. src/app/models/ProtocolBufferMessages.d.ts(492,44): error TS2304: Cannot find name 'IScores'. src/app/models/ProtocolBufferMessages.d.ts(543,36): error TS2304: Cannot find name 'IHighScores'. src/app/models/ProtocolBufferMessages.d.ts(549,30): error TS2304: Cannot find name 'IHighScores'. src/app/models/ProtocolBufferMessages.d.ts(559,39): error TS2304: Cannot find name 'IHighScores'. src/app/models/ProtocolBufferMessages.d.ts(567,35): error TS2304: Cannot find name 'IHighScores'. src/app/models/ProtocolBufferMessages.d.ts(575,44): error TS2304: Cannot find name 'IHighScores'. src/app/models/ProtocolBufferMessages.d.ts(626,36): error TS2304: Cannot find name 'ITransition'. src/app/models/ProtocolBufferMessages.d.ts(632,30): error TS2304: Cannot find name 'ITransition'. src/app/models/ProtocolBufferMessages.d.ts(645,39): error TS2304: Cannot find name 'ITransition'. src/app/models/ProtocolBufferMessages.d.ts(653,35): error TS2304: Cannot find name 'ITransition'. src/app/models/ProtocolBufferMessages.d.ts(661,44): error TS2304: Cannot find name 'ITransition'. src/app/models/ProtocolBufferMessages.d.ts(721,39): error TS2304: Cannot find name 'IReadyResponse'. src/app/models/ProtocolBufferMessages.d.ts(727,30): error TS2304: Cannot find name 'IReadyResponse'. src/app/models/ProtocolBufferMessages.d.ts(740,39): error TS2304: Cannot find name 'IReadyResponse'. src/app/models/ProtocolBufferMessages.d.ts(748,35): error TS2304: Cannot find name 'IReadyResponse'. src/app/models/ProtocolBufferMessages.d.ts(756,44): error TS2304: Cannot find name 'IReadyResponse'. src/app/services/translations/translations.service.ts(42,29): error TS2709: Cannot use namespace 'PlayerColor' as a type. src/app/services/translations/translations.service.ts(65,35): error TS2709: Cannot use namespace 'PlayerColor' as a type. src/app/services/scores/scores.service.ts(5,43): error TS2724: Module '"../../models/ProtocolBufferMessages"' has no exported member 'IPlayerScore'. Did you mean 'PlayerScore'? src/app/services/scores/scores.service.ts(97,23): error TS2709: Cannot use namespace 'PlayerColor' as a type. src/app/services/scores/scores.service.ts(98,27): error TS2709: Cannot use namespace 'PlayerColor' as a type. ```
iFwu commented 5 years ago

I have the same problem. It previously worked fine, and currently just can't generate the right d.ts. Have tried rebuilding the project, rolling back the typescript, which don't work.

zhangbuding commented 5 years ago

same problem + 1

springhack commented 5 years ago

I made a simple script to generate *.d.ts, to solve this problem for my usage https://gist.github.com/springhack/f69a7e9bd27e40e5fbf2dc6d6cffd65e

Hankszhang commented 5 years ago

same problem + 1 @dcodeIO

dcodeIO commented 5 years ago

Shot in the dark: There has been some trouble with jsdoc lately due to incompatibilities of one of its dependencies with node 12. Are the environments identical? Same node version etc.? Same package versions in node_modules?

Hankszhang commented 5 years ago

Shot in the dark: There has been some trouble with jsdoc lately due to incompatibilities of one of its dependencies with node 12. Are the environments identical? Same node version etc.? Same package versions in node_modules?

My environments are: node version: 8.15.0 protobuf.js version: 6.6.8 still got this problem

zhangbuding commented 5 years ago

Shot in the dark: There has been some trouble with jsdoc lately due to incompatibilities of one of its dependencies with node 12. Are the environments identical? Same node version etc.? Same package versions in node_modules?

node version v8.11.3 protobuf.js version v6.6.8

tgfischer commented 5 years ago

Shot in the dark: There has been some trouble with jsdoc lately due to incompatibilities of one of its dependencies with node 12. Are the environments identical? Same node version etc.? Same package versions in node_modules?

Node version: 10.15.1 NPM version: 6.4.1 ProtobufJS version: ^6.8.8

thavlik commented 5 years ago

I am having the same issue. Just moved to a new install. It's pretty inconsistent, as some protobufs will get interfaces generated for them while other do not.

iFwu commented 5 years ago

@dcodeIO It's definitely caused by some breaking changes in jsdoc. I use jsdoc 3.5.5 to replace the jsdoc 3.6.2 in protobufjs/cli/node_modules, and the result is correct.

iFwu commented 5 years ago

Quick and dirty fix: fork and change jsdoc's version from ^3.5.5 to ~3.5.5(at devDependencies in package.json file). Then install the forked version to install the correct version of jsdoc.

I've forked the repo, and can be installed using:

npm install --save protobufjs@github:iFwu/protobuf.js
digijap commented 5 years ago

Shot in the dark: There has been some trouble with jsdoc lately due to incompatibilities of one of its dependencies with node 12. Are the environments identical? Same node version etc.? Same package versions in node_modules?

Node version: v8.16.0 NPM version: 6.4.1 ProtobufJS version: 6.8.8

thavlik commented 5 years ago

Quick and dirty fix: fork and change jsdoc's version from ^3.5.5 to ~3.5.5(at devDependencies in package.json file). Then install the forked version to install the correct version of jsdoc.

I've forked the repo, and can be installed using:

npm install --save protobufjs@github:iFwu/protobuf.js

Method signatures are now messed up:

public memberName [ 'Array' ].<MemberType>;
public static verify(message: [ 'object' ].<string, any>): (string|null);
public toJSON(): [ 'object' ].<string, any>;
iFwu commented 5 years ago

Quick and dirty fix: fork and change jsdoc's version from ^3.5.5 to ~3.5.5(at devDependencies in package.json file). Then install the forked version to install the correct version of jsdoc. I've forked the repo, and can be installed using:

npm install --save protobufjs@github:iFwu/protobuf.js

Method signatures are now messed up:

public memberName [ 'Array' ].<MemberType>;
public static verify(message: [ 'object' ].<string, any>): (string|null);
public toJSON(): [ 'object' ].<string, any>;

Can you provide more specific proto file and the d.ts output? I've tried and not found such code.

thavlik commented 5 years ago

I found that downgrading to node 11 (from 12) fixed the issue. Protobufjs works for me on node 11 with the jsdoc dependency fix.

cotzo commented 3 years ago

any updates on this? I'm experiencing the same issues

antonstjernquist commented 3 years ago

This is not only an issue on Linux / Mac as the title states.

I'm experiencing this as well :/

Edit: It seems to give different results based on where the proto messages / enums is defined?

Order of these matters. Example:

enum BaseEnum {
  example = 4000
}

message BaseMessage {
  optional fixed64 id = 1;
}

System: Windows 10 Pro 32gb ram Intel Core i7-6700k

Versions: Protobuf.js: 6.10.1 NodeJS: 14.8.0 Yarn: 1.7.0

antonstjernquist commented 3 years ago

There is a PR with a fix in Jsdoc resolving this issue.

Go show it some love.

pde-rent commented 3 years ago

It is still to this day not fixed (the jsdoc PR is still not accepted), I am curious to know why. @antonstjernquist my grain of salt: Don't change anything about your .proto files, simply move all the @enum annoted enum exports to the end of your pbjs common.js bundle before running pbts (no reason to alter .proto files / imports integrity)

antonstjernquist commented 3 years ago

It is still to this day not fixed (the jsdoc PR is still not accepted), I am curious to know why. @antonstjernquist my grain of salt: Don't change anything about your .proto files, simply move all the @enum annoted enum exports to the end of your pbjs common.js bundle before running pbts (no reason to alter .proto files / imports integrity)

@pde-rent I just forked the fix and generated the files correctly. 😅 The .proto files I'm using are generated so there would be a lot of work just moving the enums unfortunately.

AJLoveChina commented 3 years ago

@pde-rent @antonstjernquist It's amazing, but I am wondering if there is anyone maintain protobufjs ? The issue has been raised two years ago....

But for protobufjs's ability to convert key-value into binary data, I think I would have used google-protobuf.

john-livelyvideo commented 3 years ago

@dcodeIO this one just hit me in the jugular, any news?