Issue Description
Regression introduced after version 2.0
When compiling proto files to TypeScript, enums are generated as const enum types. This leads to issues in frontend projects that attempt to directly import and use these enums. For example, the following usage will result in a TypeScript error:
Cannot access ambient const enums when 'verbatimModuleSyntax' is enabled.ts(2748)
Sample code:
const checkStatus = (status: SwitchStatus.Value): boolean => {
switch (status) {
case SwitchStatus.Value.CLOSE:
return false
case SwitchStatus.Value.OPEN:
return true
}
}
Previously, frontend code depended on importing these enums for type-safe logic. After recent changes (see PR #1463: fix: format of typescript definition), this is no longer possible due to the const enum generation.
Expected Behavior
- Frontend should be able to import generated proto enums and use them directly in TypeScript code without errors, regardless of TypeScript config such as
verbatimModuleSyntax.
Actual Behavior
- Importing generated enums causes build errors, breaking existing frontend usage patterns.
Related PR
Suggestions
- Consider generating regular
enum instead of const enum to maximize compatibility
- Or provide a configuration option to choose between
const enum and regular enum generation
Environment
- TypeScript with
verbatimModuleSyntax enabled (this's default option with TypeScript 5.9)
- Frontend project importing generated proto enums
- grpc-web version: experiencing issues since version 2.0
- Currently reverted to version 1.5 as temporary workaround
Additional Context
- This issue affects all frontend codebases relying on direct enum imports from generated proto definitions.
- Temporary workaround: Reverted to grpc-web 1.5 to prevent project breakage
- Breaking change impact: This prevents teams from upgrading to newer versions due to frontend compatibility issues
Issue Description
Regression introduced after version 2.0
When compiling proto files to TypeScript, enums are generated as
const enumtypes. This leads to issues in frontend projects that attempt to directly import and use these enums. For example, the following usage will result in a TypeScript error:Sample code:
Previously, frontend code depended on importing these enums for type-safe logic. After recent changes (see PR #1463: fix: format of typescript definition), this is no longer possible due to the
const enumgeneration.Expected Behavior
verbatimModuleSyntax.Actual Behavior
Related PR
Suggestions
enuminstead ofconst enumto maximize compatibilityconst enumand regularenumgenerationEnvironment
verbatimModuleSyntaxenabled (this's default option with TypeScript 5.9)Additional Context