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

Compilation error when combining useOptionals=all with forceLong=long #945

Closed
vecerek opened this issue Oct 9, 2023 · 1 comment · Fixed by #949
Closed

Compilation error when combining useOptionals=all with forceLong=long #945

vecerek opened this issue Oct 9, 2023 · 1 comment · Fixed by #949
Labels

Comments

@vecerek
Copy link
Contributor

vecerek commented Oct 9, 2023

Steps to reproduce

// example.proto

syntax = "proto3";

import "google/protobuf/timestamp.proto";

message Example {
  google.protobuf.Timestamp datetime = 1;
}

and then run:

protoc \
  --plugin=./node_modules/.bin/protoc-gen-ts_proto \
  --ts_proto_opt=useOptionals=all \
  --ts_proto_opt=forceLong=long \
  --ts_proto_out=. \
  example.proto

The generated ts file will have a compilation error in the following function:

function fromTimestamp(t: Timestamp): Date {
  let millis = (t.seconds.toNumber() || 0) * 1_000;
//              ^^^^^^^^^
//              't.seconds' is possibly 'undefined'.ts(18048)
  millis += (t.nanos || 0) / 1_000_000;
  return new globalThis.Date(millis);
}

Expected output

function fromTimestamp(t: Timestamp): Date {
  let millis = (t.seconds?.toNumber() || 0) * 1_000;
  millis += (t.nanos || 0) / 1_000_000;
  return new globalThis.Date(millis);
}
@stephenh
Copy link
Owner

🎉 This issue has been resolved in version 1.161.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

2 participants