timostamm / protobuf-ts

Protobuf and RPC for TypeScript
Apache License 2.0
1.09k stars 130 forks source link

unused parameters in the empty.ts are causing TypeScript check errors #608

Closed tidycode closed 11 months ago

tidycode commented 11 months ago

This empty.ts was auto generated from protobuf file "google/protobuf/empty.proto" (package "google.protobuf", syntax proto3)

the error is in the function internalBinaryRead image

    internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Empty): Empty {
        return target ?? this.create();
    }

if run script vue-tsc --noEmit --skipLibCheck It will cause ts-check error 'reader' is declared but its value is never read. 'length' is declared but its value is never read. 'options' is declared but its value is never read.

danielvandenberg95 commented 11 months ago

It's not only in empty.ts. It's in any proto message without members. A solution would be to prefix unused variables with _.

Use-case: I've got multiple empty types because I expect to add members in the future.

danielvandenberg95 commented 11 months ago

https://github.com/timostamm/protobuf-ts/pull/609

danielvandenberg95 commented 11 months ago

As timostamm suggested there, generate proto with --ts_opt ts_nocheck.

tidycode commented 11 months ago

As timostamm suggested there, generate proto with --ts_opt ts_nocheck.

thanks ,but where is the --ts_opt that I can add? I use buf.gen.yaml

version: v1
plugins:
  - plugin: buf.build/community/timostamm-protobuf-ts:v2.9.1
    out: ./ts

if run
buf generate --ts_opt ts_nocheck will throw error: unknown flag: --ts_opt

timostamm commented 11 months ago

See the documentation here.

version: v1
plugins:
  - plugin: buf.build/community/timostamm-protobuf-ts:v2.9.1
    out: ./ts
    opt: ts_nocheck

For multiple plugin options, use:

version: v1
plugins:
  - plugin: ...
    out: ...
    opt: 
      - ts_nocheck
      - other_option
tidycode commented 11 months ago
opt: ts_nocheck

Many thanks, now it works! empty.ts before

// @generated by protobuf-ts 2.9.1 with parameter ts_nocheck
// @generated from protobuf file "google/protobuf/empty.proto" (package "google.protobuf", syntax proto3)
// tslint:disable
......

empty.ts after

// @generated by protobuf-ts 2.9.1 with parameter ts_nocheck
// @generated from protobuf file "google/protobuf/empty.proto" (package "google.protobuf", syntax proto3)
// tslint:disable
// @ts-nocheck
......

and also thanks @danielvandenberg95 I think https://github.com/timostamm/protobuf-ts/pull/609. is a good PR