v1.2.1 generates incorrect code for enum type (missing leading character)
See original GitHub issueUpgrading 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;
~~~~
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
Top Results From Across the Web
Error "Operator '===' cannot be applied to types" with enum type
TypeScript Version: 2.0.3 Code enum SomeEnum { V1, V2 } class ... I'm getting the same error with the following code ( tsc...
Read more >"Invalid character" in enum declaration - Stack Overflow
While pasting, hidden invalid character was added, and that's why the error occurs. Try to write the code from scratch and see if...
Read more >Enum - Java Programming Tutorial
An enumeration is a special type, which provides a type-safe implementation of constants in your program. In other words, we can declare a...
Read more >Opayo Pi API Reference - Elavon Developer Portal
The current version of the Opayo API is v1, as defined in the base URL. ... 401, Unauthorised, Authentication credentials are missing or...
Read more >Hibernate ORM 5.2.18.Final User Guide - Red Hat on GitHub
Hibernate supports the mapping of Java enums as basic value types in a number of ... ( 'F' ); private final char code;...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hurray! I will check this out as soon as I am able. Thank you!
Hi there. Will this fix be integrated into a release anytime soon? If not, are there any instructions available for building the plugin from scratch, since those are not in the main README? (I get a permissions error on grpcweb/prereqs when I try to build via the Docker image in the project.)
Currently our build script is repairing each broken enum name manually using a
sed
command, but this is not a sustainable practice.Thank you!