CosmWasm / ts-codegen

Convert your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.
https://cosmology.zone/products/ts-codegen
Apache License 2.0
116 stars 29 forks source link

Generated ts client files misses override modifier #78

Closed dadamu closed 2 years ago

dadamu commented 2 years ago

The generated client file from json schema from cw_serde could not work properly since it misses the override modifier. For instance, the generated Poap.client.ts shows:

export class PoapQueryClient implements PoapReadOnlyInterface {
  client: CosmWasmClient;
  contractAddress: string;

  methods...
}
export class PoapClient extends PoapQueryClient implements PoapInterface {
  client: SigningCosmWasmClient;
  sender: string;
  contractAddress: string;

  methods...
}

Then, thhe error shows:

../types/contracts/poap/Poap.client.ts:133:3 - error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'PoapQueryClient'.

133   client: SigningCosmWasmClient;
      ~~~~~~
../types/contracts/poap/Poap.client.ts:135:3 - error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'PoapQueryClient'.

135   contractAddress: string;

After adding override modifier to PoapClient property can solve the issue, like:

export class PoapClient extends PoapQueryClient implements PoapInterface {
  override client: SigningCosmWasmClient;
  sender: string;
  override contractAddress: string;

  methods...
}
pyramation commented 2 years ago

hi @dadamu are do you happen to have a method of the same name in both your ExecuteMsg and QueryMsg?

dadamu commented 2 years ago

@pyramation No, they don't have the same name, the example contract is here. However PoapClient and PoapQueryClient has the same name properties generated by ts-codegen, client and contractAddress. I added override manually then solved the issue.

pyramation commented 2 years ago

I will look into making an option for this.

In the meantime, it looks like you can also set noImplicitOverride to false in your tsconfig.json

pyramation commented 2 years ago

tracking here https://github.com/CosmWasm/ts-codegen/pull/79

pyramation commented 2 years ago

just create a new option client.noImplicit.noImplicitOverride you can set to true.

Defaults to false to keep backwards compat for now.

Successfully published:
 - @cosmwasm/ts-codegen@0.21.0
 - wasm-ast-types@0.15.0
dadamu commented 2 years ago

@pyramation Thanks for the help!