improbable-eng / ts-protoc-gen

Protocol Buffers Compiler (protoc) plugin for TypeScript and gRPC-Web.
Apache License 2.0
1.36k stars 173 forks source link

"google.protobuf.NullValue" from "google/protobuf/struct.proto" is not supported #250

Open mdreizin opened 3 years ago

mdreizin commented 3 years ago

Versions of relevant software used

ts-protoc-gen@0.13.0 google-protobuf@3.14.0 @types/google-protobuf@3.7.4

What happened

Generate wrong TypeScript definition, because google_protobuf_struct_pb.NullValueMap doesn't exist:

import * as jspb from "google-protobuf";
import * as google_protobuf_struct_pb from "google-protobuf/google/protobuf/struct_pb";

export class MyMessage extends jspb.Message {
  getValue(): google_protobuf_struct_pb.NullValueMap[keyof google_protobuf_struct_pb.NullValueMap];
  setValue(value: google_protobuf_struct_pb.NullValueMap[keyof google_protobuf_struct_pb.NullValueMap]): void;

  serializeBinary(): Uint8Array;
  toObject(includeInstance?: boolean): MyMessage.AsObject;
  static toObject(includeInstance: boolean, msg: MyMessage): MyMessage.AsObject;
  static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
  static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
  static serializeBinaryToWriter(message: MyMessage, writer: jspb.BinaryWriter): void;
  static deserializeBinary(bytes: Uint8Array): MyMessage;
  static deserializeBinaryFromReader(message: MyMessage, reader: jspb.BinaryReader): MyMessage;
}

export namespace MyMessage {
  export type AsObject = {
    value: google_protobuf_struct_pb.NullValueMap[keyof google_protobuf_struct_pb.NullValueMap],
  }
}

What you expected to happen

Generate right TypeScript definition.

If use the following proto:

syntax = "proto3";

enum NullValue {
  NULL_VALUE = 0;
}

message MyMessage {
  oneof kind {
    NullValue value = 1;
  }
}

it will generate right definition:

import * as jspb from "google-protobuf";

export class MyMessage extends jspb.Message {
  hasValue(): boolean;
  clearValue(): void;
  getValue(): NullValueMap[keyof NullValueMap];
  setValue(value: NullValueMap[keyof NullValueMap]): void;

  getKindCase(): MyMessage.KindCase;
  serializeBinary(): Uint8Array;
  toObject(includeInstance?: boolean): MyMessage.AsObject;
  static toObject(includeInstance: boolean, msg: MyMessage): MyMessage.AsObject;
  static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
  static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
  static serializeBinaryToWriter(message: MyMessage, writer: jspb.BinaryWriter): void;
  static deserializeBinary(bytes: Uint8Array): MyMessage;
  static deserializeBinaryFromReader(message: MyMessage, reader: jspb.BinaryReader): MyMessage;
}

export namespace MyMessage {
  export type AsObject = {
    value: NullValueMap[keyof NullValueMap],
  }

  export enum KindCase {
    KIND_NOT_SET = 0,
    VALUE = 1,
  }
}

export interface NullValueMap {
  NULL_VALUE: 0;
}

export const NullValue: NullValueMap;

How to reproduce it (as minimally and precisely as possible):

syntax = "proto3";

import "google/protobuf/struct.proto";

message MyMessage {
    google.protobuf.NullValue value = 1;
}

Full logs to relevant components

Anything else we need to know

stale[bot] commented 2 years ago

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.

jimblackler commented 1 year ago

I have experienced the same issue recently.

tfennelly commented 1 month ago

I'm seeing the same issue.

Did either of you get a resolution to this? @jimblackler @mdreizin