Type Error when QueryMsg and ExecuteMsg share a same enum name
augustbleeds opened this issue · 2 comments
Found this when trying to generate types for the cw3-flex-multisig contract:
There is both a "Vote" enum value for the QueryMsg and Execute Msg (https://github.com/CosmWasm/cw-plus/blob/main/contracts/cw3-flex-multisig/src/msg.rs#L32) so when ts-codegen generates the client class, the "vote" execute method it shares the same name as "vote" query method.
Perhaps we should add an optional field in codegen.js to prepend an "exec_" or "query_" to associated methods?
packages-ts/gauntlet-cosmos-contracts/codegen/CW3FlexMultisig.client.ts:179:18 - error TS2430: Interface 'CW3FlexMultisigInterface' incorrectly extends interface 'CW3FlexMultisigReadOnlyInterface'.
Types of property 'vote' are incompatible.
Type '({ proposalId, vote }: { proposalId: number; vote: Vote; }, fee?: number | StdFee | "auto" | undefined, memo?: string | undefined, _funds?: Coin[] | undefined) => Promise<ExecuteResult>' is not assignable to type '({ proposalId, voter }: { proposalId: number; voter: string; }) => Promise<VoteResponse>'.
Types of parameters '__0' and '__0' are incompatible.
Property 'vote' is missing in type '{ proposalId: number; voter: string; }' but required in type '{ proposalId: number; vote: Vote; }'.
179 export interface CW3FlexMultisigInterface extends CW3FlexMultisigReadOnlyInterface {
~~~~~~~~~~~~~~~~~~~~~~~~
packages-ts/gauntlet-cosmos-contracts/codegen/CW3FlexMultisig.client.ts:198:5
198 vote: Vote;
~~~~
'vote' is declared here.
packages-ts/gauntlet-cosmos-contracts/codegen/CW3FlexMultisig.client.ts:253:3 - error TS2416: Property 'vote' in type 'CW3FlexMultisigClient' is not assignable to the same property in base type 'CW3FlexMultisigQueryClient'.
Type '({ proposalId, vote }: { proposalId: number; vote: Vote; }, fee?: number | StdFee | "auto", memo?: string | undefined, _funds?: Coin[] | undefined) => Promise<ExecuteResult>' is not assignable to type '({ proposalId, voter }: { proposalId: number; voter: string; }) => Promise<VoteResponse>'.
Types of parameters '__0' and '__0' are incompatible.
Property 'vote' is missing in type '{ proposalId: number; voter: string; }' but required in type '{ proposalId: number; vote: Vote; }'.
253 vote = async ({
~~~~
packages-ts/gauntlet-cosmos-contracts/codegen/CW3FlexMultisig.client.ts:258:5
258 vote: Vote;
~~~~
'vote' is declared here.
I can open a PR if that sounds good
I guess current workaround is to do execExtendsQuery: false so the inheritance doesn't occur -- but then you have to work with two clients
You guys can use this tools, it supports queryPrefixOnConflict option to solve that: https://github.com/oraichain/cosmwasm-tools/blob/main/src/cmd/gents.ts#L32