Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
LavissaWoW opened this issue Jul 15, 2024 · 1 comment · Fixed by #2010
Closed

Comments

@LavissaWoW
Copy link

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.

@LavissaWoW
Copy link
Author

I'm happy to whip up a short PR to address the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant