Skip to content

v1.2.1 generates incorrect code for enum type (missing leading character) #1039

@meling

Description

@meling

Upgrading from v1.2.0 to v1.2.1 results in non-compilable code in _pb.d.ts.

The following (minimized) proto file compiles fine with v1.2.0:

syntax = "proto3";

message Group {
    enum GroupStatus {
        PENDING = 0;
        APPROVED = 1;
    }
    uint64 ID = 1;
    GroupStatus status = 2;
}

The generated code looks like this:

...
  getStatus(): roup.GroupStatus;
  setStatus(value: roup.GroupStatus): Group;
...
export namespace Group {
  export type AsObject = {
    id: number,
    status: roup.GroupStatus,
  }

  export enum GroupStatus { 
    PENDING = 0,
    APPROVED = 1,
  }
}

As can be seen, references to the encapsulated enum type roup.GroupStatus should be Group.GroupStatus. A similar problem happens if the enum type is moved outside the Group message:

export namespace Group {
  export type AsObject = {
    id: number,
    status: roupStatus,
  }
}

export enum GroupStatus { 
  PENDING = 0,
  APPROVED = 1,
}

Command used to compile (works fine with v1.2.0):

% protoc -I=. -I=$(pbpath) \
	--js_out=import_style=commonjs:../$(proto-path)/ \
	--grpc-web_out=import_style=typescript,mode=grpcweb:../$(proto-path)/ ag.proto

This results in compile errors similar to this (included for people searching for this error message):

proto/ag_pb.d.ts:9:16 - error TS2503: Cannot find namespace 'roup'.

9   getStatus(): roup.GroupStatus;
                 ~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions