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

Change return type of generated setters to the message type #281

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

craigatron
Copy link

Changes

  • message.ts - changed return type of generated setters to ${messageName}
  • ran npm run generate to regenerate example proto generated code
  • added tests that chain setter calls and verify value on generated object

Verification

Added unit tests for chained setter methods.

@improbable-prow-robot improbable-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 21, 2021
@improbable-prow-robot improbable-prow-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/XXL Denotes a PR that changes 600+ lines, ignoring generated files. labels Jun 21, 2021
@craigatron craigatron marked this pull request as ready for review June 21, 2021 19:25
@improbable-prow-robot improbable-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 21, 2021
@@ -184,12 +184,12 @@ export function printMessage(fileName: string, exportMap: ExportMap, messageDesc
printer.printIndentedLn(`get${withUppercase}List(): Array<Uint8Array | string>;`);
printer.printIndentedLn(`get${withUppercase}List_asU8(): Array<Uint8Array>;`);
printer.printIndentedLn(`get${withUppercase}List_asB64(): Array<string>;`);
printer.printIndentedLn(`set${withUppercase}List(value: Array<Uint8Array | string>): void;`);
printer.printIndentedLn(`set${withUppercase}List(value: Array<Uint8Array | string>): ${messageName};`);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the Protoc docs:

addFoo(): Appends a value of foo to the end of the list of foos that was in the message. Returns the outer message for chaining only if the added value was a primitive. For added messages, returns the message that was added (b/138079947).

https://developers.google.com/protocol-buffers/docs/reference/javascript-generated

My understanding is this means the return type of setInternalChildMessage for example should be the child message type, and not the parent message type.

        // Wrong 
        setInternalChildMessage(value?: OneOfMessage.InternalChildMessage): OneOfMessage;
        
        // Correct
        setInternalChildMessage(value?: OneOfMessage.InternalChildMessage): OneOfMessage.InternalChildMessage;

Can you add some test cases to verify this?

@gecko655
Copy link

gecko655 commented Aug 18, 2021

This fix is seriously important for the ts-protoc-gen users (and me).
It seems that fixes and tests are good enough (for me).
Would it be possible for the maintainers to review again?

Note: This PR fixes #218 #285 .

Update:
This PR also fixes #289

@improbable-prow-robot improbable-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 8, 2021
@improbable-prow-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MarcusLongmuir

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@improbable-prow-robot improbable-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 8, 2021
@chris-codaio
Copy link

Just ran into this issue trying to update definitions. It looks like this PR is approved - any reason it can't be checked in and pushed out in a new version? Anything I can do to help?

@thompsonja
Copy link

thompsonja commented Aug 10, 2022

Bumping this PR... is there any reason this can't be merged?

@gonzojive
Copy link

bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 600+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants