Skip to content

Type Error when QueryMsg and ExecuteMsg share a same enum name #130

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

Closed
augustbleeds opened this issue Aug 11, 2023 · 2 comments
Closed

Type Error when QueryMsg and ExecuteMsg share a same enum name #130

augustbleeds opened this issue Aug 11, 2023 · 2 comments

Comments

@augustbleeds
Copy link

augustbleeds commented Aug 11, 2023

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

@augustbleeds
Copy link
Author

augustbleeds commented Aug 11, 2023

I guess current workaround is to do execExtendsQuery: false so the inheritance doesn't occur -- but then you have to work with two clients

@tubackkhoa
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants