Skip to content

pbts generating syntax error on types when using multi-line @typedefs in static code #2009

Closed
@LavissaWoW

Description

@LavissaWoW

protobuf.js version: 7.3.0

Using @typedef definitions on static code generates invalid type syntax.
Any property after the first declared property will be prefixed with let

/**
 * @typedef {Object} MyType
 * @property {string} prop1
 * @property {number} prop2
 * @property {number] prop3
 */

When running pbts, this will be converted to:

type MyType = {
  prop1: string;
  let prop2: number;
  let prop3: number;
}

This isn't valid type syntax.

The problem occurs here:

else if (element.properties && element.properties.length)
element.properties.forEach(writeProperty);
--indent;

forEach passes (value, index), and writePropertys second argument declare will then be populated with index.

function writeProperty(property, declare) {
writeComment(property.description);
if (declare)
write("let ");
write(property.name);

Thus, the declare condition will be true for every element past array index 0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions