ts-protoc-gen icon indicating copy to clipboard operation
ts-protoc-gen copied to clipboard

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

Open mdreizin opened this issue 5 years ago • 3 comments

Versions of relevant software used

[email protected] [email protected] @types/[email protected]

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

mdreizin avatar Dec 04 '20 11:12 mdreizin

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[bot] avatar Apr 17 '22 07:04 stale[bot]

I have experienced the same issue recently.

jimblackler avatar Jul 27 '23 10:07 jimblackler