grpc / grpc/grpc-node

Autogenerated code erro: Cannot use namespace 'Long' as a type

Open
#2,617 15 comments 6 reactions 0 assignees View on GitHub
package: @grpc/proto-loader
Dominant language
TypeScript
Stars
4.8k
Forks
716
Avg merge
2d 3h
Merged PRs (30d)
10

Description

### Problem description
The autogenerated type code from `@grpc/grpc-js` is generating code that is not valid typescript.

## Example Error
For example, the `Long` that is imported causes an error:
![CleanShot 2023-11-15 at 07 18 39@2x](https://github.com/grpc/grpc-node/assets/6743796/2a443e48-1e43-431a-a250-f93ff783696c)

I edited the autogenerated file by using `typeof Long` further below in the code & that made the typescript error go away.
This works because [Namespaces can be converted to types using the `typeof` keyword](https://stackoverflow.com/a/70779907).

![CleanShot 2023-11-15 at 07 19 34@2x](https://github.com/grpc/grpc-node/assets/6743796/8a27e3fd-e4ef-41db-a32b-21b5d998c476)

### Reproduction steps
Work in progress

This is what my settings for generating types looks like using @grpc/proto-loader
https://www.npmjs.com/package/@grpc/proto-loader#generating-typescript-types

```sh
yarn run proto-loader-gen-types \
-I $PROTOS_DESTINATION_DIR/serviceProto \
-I $PROTOS_DESTINATION_DIR \
--keepCase \
--longs=String \
--enums=String \
--defaults \
--oneofs \
--grpcLib=@grpc/grpc-js \
--outDir=$PROTOS_DESTINATION_DIR \
$PROTOS_DESTINATION_DIR/serviceProto/proto/com/linkedin/euler/controlplane/*.proto

```

### Environment
OS Name: Sonomo 14.1.1
Node version 20.5.0
Typrscript: 5.0.4
@grpc/grpc-js": "1.9.9",
@grpc/proto-loader": "0.7.10",

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.