-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import Long from 'long'; even when long option is number #330
Comments
Yeah, that's surprising, can you paste a snippet of the code that has |
Here's an outputted file including /* eslint-disable */
import { GrpcMethod, GrpcStreamMethod } from '@nestjs/microservices';
import Long from 'long';
import _m0 from 'protobufjs/minimal';
import { Observable } from 'rxjs';
import { Metadata } from '@grpc/grpc-js';
export const protobufPackage = 'hero';
export interface HeroById {
id: number;
}
export interface Hero {
id: number;
name: string;
}
export const HERO_PACKAGE_NAME = 'hero';
export interface HeroesServiceClient {
findOne(
request: HeroById,
metadata: Metadata,
...rest: any
): Observable<Hero>;
}
export interface HeroesServiceController {
findOne(
request: HeroById,
metadata: Metadata,
...rest: any
): Observable<Hero>;
}
export function HeroesServiceControllerMethods() {
return function (constructor: Function) {
const grpcMethods: string[] = ['findOne'];
for (const method of grpcMethods) {
const descriptor: any = Reflect.getOwnPropertyDescriptor(
constructor.prototype,
method,
);
GrpcMethod('HeroesService', method)(
constructor.prototype[method],
method,
descriptor,
);
}
const grpcStreamMethods: string[] = [];
for (const method of grpcStreamMethods) {
const descriptor: any = Reflect.getOwnPropertyDescriptor(
constructor.prototype,
method,
);
GrpcStreamMethod('HeroesService', method)(
constructor.prototype[method],
method,
descriptor,
);
}
};
}
export const HEROES_SERVICE_NAME = 'HeroesService';
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
} Here is the
Version: 1.82.2 grpc_tools_node_protoc \
--plugin=./node_modules/.bin/protoc-gen-ts_proto \
--ts_proto_opt=env=node \
--ts_proto_opt=useOptionals=true \
--ts_proto_opt=useDate=true \
--ts_proto_opt=forceLong=number \
--ts_proto_opt=returnObservable=true \
--ts_proto_opt=addGrpcMetadata=true \
--ts_proto_opt=addNestjsRestParameter=true \
--ts_proto_opt=nestJs=true \
--ts_proto_opt=outputServices=grpc-js \
--ts_proto_opt=esModuleInterop=true \
--ts_proto_out="${OUT_DIR}" \
-I=./proto ./proto/**/*.proto |
Ah, you don't have You're using NestJS to encoding & decoding, do you know if it uses the For ts-proto itself, even if you use So that's why ts-proto is always init'ing this The wrinkle you have is that, with Are you 100% sure the NestJS doesn't use If it does, we should probably leave this code here. If not, we could omit it. I'm tempted to assert it's not really doing any harm? |
I'd like to be able to generate just Typescript interfaces without any dependencies or imports at all. At the moment the generated file include import Long from "long";
import _m0 from "protobufjs/minimal"; and if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
} even though the interfaces all look something like this export interface ServerLogRecord {
version: string;
tick: number;
eventType: string;
data?: DataObject;
}
export interface DataObject {
objectName: string;
variant?: ObjectVariant| undefined;
} So it would be really great if there was a way to disable unecessary imports. I'm using protoc 3.19.1, ts-proto 1.83.3, and these options
|
Hey @aSemy , yeah, that makes sense; https://protobufjs.github.io/protobuf.js/#compatibility So anytime The other ideal option would be to use Bigints, but ts-proto doesn't support those yet: #64 |
Replacing |
Hm, yeah, that does seem unexpected; we could probably add https://github.com/stephenh/ts-proto/blob/main/src/main.ts#L295 @aSemy do you want to submit a PR for ^? |
I'm not sure what you mean, I'm not very familiar with Typescript, and I don't understand the existing code. Is this what you mean? const longInit = options.onlyTypes
? code``
: code`
${disclaimer}
if (${util}.Long !== ${Long} || forceLong === string) {
${util}.Long = ${Long} as any;
${configure}();
}
`; |
Importing long is emitted even though the long format is number.
Version: 1.81.3
options:
The text was updated successfully, but these errors were encountered: