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

Fix TypeScript annotations for setters #289

Open
roboslone opened this issue Sep 28, 2021 · 4 comments
Open

Fix TypeScript annotations for setters #289

roboslone opened this issue Sep 28, 2021 · 4 comments

Comments

@roboslone
Copy link

Currently there's no way to chain setters, because they don't return anything.
It would be convenient to have setters return the object they're called on:

// Current
const message = new Message()
message.setName('name')
message.setCount(1)

const subMessage = new SubMessage()
subMessage.setName('sub')
message.setSubMessage(subMessage)

// Proposed
const message = new Message()
    .setName('name')
    .setCount(1)
    .setSubMessage(new SubMessage().setName('sub'))
@roboslone
Copy link
Author

UPD I've checked generated JS code and it seems that JS actually returns this. TypeScript annotations have void though.

/**
 * @param {string} value
 * @return {!proto.MyMessage} returns this
 */
proto.MyMessage.prototype.setSymbol = function(value) {
  return jspb.Message.setProto3StringField(this, 1, value);
};

export class MyMessage extends jspb.Message {
  setSymbol(value: string): void;
}

@roboslone roboslone changed the title Return this from setters Fix TypeScript annotations for setters Sep 28, 2021
@stale
Copy link

stale bot commented Apr 17, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 17, 2022
@roboslone
Copy link
Author

It's still relevant.

@stale stale bot removed the wontfix label Apr 17, 2022
@reddaly
Copy link

reddaly commented Jul 29, 2022

The fix should be relatively easy. The file to modify is here: https://github.com/improbable-eng/ts-protoc-gen/blob/master/src/ts/message.ts

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

No branches or pull requests

2 participants