cosmology-tech / telescope

A TypeScript Transpiler for Cosmos Protobufs ⚛️
https://cosmology.zone/products/telescope
Apache License 2.0
145 stars 43 forks source link

Transpile generating types with different writers #482

Open Ange-FE opened 1 year ago

Ange-FE commented 1 year ago

Transpile generating types with different writers resulting in code that cannot be used due to mismatch of types,

Type error: Type '{ typeUrl: string; encode(message: MsgGrant, writer?: BinaryWriter): BinaryWriter; decode(input: Uint8Array | BinaryReader, length?: number): MsgGrant; ... 7 more ...; toProtoMsg(message: MsgGrant): MsgGrantProtoMsg; }' is not assignable to type 'GeneratedType'.

steps to replicate:

  1. Download and install telescope v1.0.3
  2. Telescope
  3. generate
  4. install
  5. select the following packages cosmos, cosmos_proto, gogoproto, google, tendermint
  6. Transpile,
  7. open up generated code in src/codegen
  8. open/browse cosmos/bank/v1beta/tx.registry.ts
  9. error will be on MsgSend , MsgMultiSend
  10. Type '{ typeUrl: string; encode(message: MsgSend, writer?: BinaryWriter): BinaryWriter; decode(input: BinaryReader | Uint8Array, length?: number): MsgSend; ... 7 more ...; toProtoMsg(message: MsgSend): MsgSendProtoMsg; }' is not assignable to type 'GeneratedType'.
Zetazzz commented 1 year ago

Hi, please excuse us that we haven't got chance to fix this yet. There's a work around for this:

tsDisable: {
      patterns: ["**/tx.registry.ts"],
}

We can use tsDisable for compilation errors in files.

Hope this could help

Thank you very much!

Zetazzz commented 1 year ago

recently we posted this PR for this: https://github.com/cosmology-tech/telescope/pull/488

Ange-FE commented 1 year ago

I have noticed that version 1.0.11 has issues again with generating the types with different writer types

Zetazzz commented 1 year ago

Ok...I believe with these configs there shouldn't be the problem:

prototypes.typingsFormat.useTelescopeGeneratedType: true prototypes.enableRegistryLoader: false

ducksquaddd commented 1 year ago

Still getting this issue myself

junhoyeo commented 8 months ago

My solution was to turn off options.interfaces.enabled while enabling options.prototypes.typingsFormat.useTelescopeGeneratedType:

telescope({
  protoDirs,
  outPath,

  options: {
    interfaces: {
-     enabled: true,
+     enabled: false,
      useUnionTypes: false,
    },
    prototypes: {
      includePackageVar: false,
      addTypeUrlToDecoders: true,
      typingsFormat: {
        useDeepPartial: false,
        useExact: false,
        timestamp: 'timestamp',
        duration: 'duration',
+       useTelescopeGeneratedType: true,
      },
      methods: { toJSON: true, fromJSON: true },
    },
    lcdClients: { enabled: false },
    rpcClients: { enabled: false },
  },
})
assafmo commented 4 months ago

Simply setting useTelescopeGeneratedType=true fixed it for me with telescope v1.8.3