Skip to content
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

IDL: Types with generics are not assignable to parameter of type Idl #2687

Closed
vadorovsky opened this issue Oct 28, 2023 · 1 comment
Closed
Labels
idl related to the IDL, either program or client side ts

Comments

@vadorovsky
Copy link
Contributor

vadorovsky commented Oct 28, 2023

When upgrading Light Protocol to Anchor 0.29, I encountered the following error, when using the IDL const as Idl type:

       src/multisigParams.ts(140,40): error TS2345: Argument of type 'Multisig' is not assignable to parameter of type 'Idl'.
         Types of property 'accounts' are incompatible.
           Type '[{ name: "eventMerkleTree"; type: { kind: "struct"; fields: [{ name: "merkleTreeNr"; type: "u64"; }, { name: "newest"; type: "u8"; }, { name: "padding"; type: { array: ["u8", 7]; }; }, { name: "merkleTree"; type: { ...; }; }]; }; }, { ...; }, { ...; }]' is not assignable to type 'IdlAccountDef[]'.
             Type '{ name: "eventMerkleTree"; type: { kind: "struct"; fields: [{ name: "merkleTreeNr"; type: "u64"; }, { name: "newest"; type: "u8"; }, { name: "padding"; type: { array: ["u8", 7]; }; }, { name: "merkleTree"; type: { ...; }; }]; }; } | { ...; } | { ...; }' is not assignable to type 'IdlAccountDef'.
               Type '{ name: "eventMerkleTree"; type: { kind: "struct"; fields: [{ name: "merkleTreeNr"; type: "u64"; }, { name: "newest"; type: "u8"; }, { name: "padding"; type: { array: ["u8", 7]; }; }, { name: "merkleTree"; type: { ...; }; }]; }; }' is not assignable to type 'IdlAccountDef'.
                 The types of 'type.fields' are incompatible between these types.
                   Type '[{ name: "merkleTreeNr"; type: "u64"; }, { name: "newest"; type: "u8"; }, { name: "padding"; type: { array: ["u8", 7]; }; }, { name: "merkleTree"; type: { definedWithTypeArgs: { name: "MerkleTreeSha256"; args: [...]; }; }; }]' is not assignable to type 'IdlTypeDefStruct'.
                     Type '{ name: "merkleTreeNr"; type: "u64"; } | { name: "newest"; type: "u8"; } | { name: "padding"; type: { array: ["u8", 7]; }; } | { name: "merkleTree"; type: { definedWithTypeArgs: { name: "MerkleTreeSha256"; args: [...]; }; }; }' is not assignable to type 'IdlField'.
                       Type '{ name: "merkleTree"; type: { definedWithTypeArgs: { name: "MerkleTreeSha256"; args: [{ value: "18"; }, { value: "20"; }]; }; }; }' is not assignable to type 'IdlField'.
                         Types of property 'type' are incompatible.
                           Type '{ definedWithTypeArgs: { name: "MerkleTreeSha256"; args: [{ value: "18"; }, { value: "20"; }]; }; }' is not assignable to type 'IdlType'.
       src/multisigParams.ts(145,40): error TS2345: Argument of type 'Multisig' is not assignable to parameter of type 'Idl'.
       src/transaction.ts(35,42): error TS2345: Argument of type 'Multisig' is not assignable to parameter of type 'Idl'.
       src/transaction.ts(40,42): error TS2345: Argument of type 'Multisig' is not assignable to parameter of type 'Idl'.
       src/client.ts(51,21): error TS2344: Type 'Multisig' does not satisfy the constraint 'Idl'.
       src/client.ts(77,5): error TS2322: Type 'Program<Idl>' is not assignable to type 'Program<Multisig>'.
         Types of property 'account' are incompatible.
           Type 'AccountNamespace<Idl>' is missing the following properties from type 'AccountNamespace<Multisig>': transactionMerkleTree, eventMerkleTree, verifierState10Ins
       src/client.ts(77,33): error TS2345: Argument of type 'Multisig' is not assignable to parameter of type 'Idl'.
       src/client.ts(212,9): error TS2322: Type 'Multisig' is not assignable to type 'Idl'.
         Types of property 'accounts' are incompatible.
           Type '[{ name: "eventMerkleTree"; type: { kind: "struct"; fields: [{ name: "merkleTreeNr"; type: "u64"; }, { name: "newest"; type: "u8"; }, { name: "padding"; type: { array: ["u8", 7]; }; }, { name: "merkleTree"; type: { ...; }; }]; }; }, { ...; }, { ...; }]' is not assignable to type 'IdlAccountDef[]'.
             Type '{ name: "eventMerkleTree"; type: { kind: "struct"; fields: [{ name: "merkleTreeNr"; type: "u64"; }, { name: "newest"; type: "u8"; }, { name: "padding"; type: { array: ["u8", 7]; }; }, { name: "merkleTree"; type: { ...; }; }]; }; } | { ...; } | { ...; }' is not assignable to type 'IdlAccountDef'.
               Type '{ name: "eventMerkleTree"; type: { kind: "struct"; fields: [{ name: "merkleTreeNr"; type: "u64"; }, { name: "newest"; type: "u8"; }, { name: "padding"; type: { array: ["u8", 7]; }; }, { name: "merkleTree"; type: { ...; }; }]; }; }' is not assignable to type 'IdlAccountDef'.
                 The types of 'type.fields' are incompatible between these types.
                   Type '[{ name: "merkleTreeNr"; type: "u64"; }, { name: "newest"; type: "u8"; }, { name: "padding"; type: { array: ["u8", 7]; }; }, { name: "merkleTree"; type: { definedWithTypeArgs: { name: "MerkleTreeSha256"; args: [...]; }; }; }]' is not assignable to type 'IdlTypeDefStruct'.
                     Type '{ name: "merkleTreeNr"; type: "u64"; } | { name: "newest"; type: "u8"; } | { name: "padding"; type: { array: ["u8", 7]; }; } | { name: "merkleTree"; type: { definedWithTypeArgs: { name: "MerkleTreeSha256"; args: [...]; }; }; }' is not assignable to type 'IdlField'.
                       Type '{ name: "merkleTree"; type: { definedWithTypeArgs: { name: "MerkleTreeSha256"; args: [{ value: "18"; }, { value: "20"; }]; }; }; }' is not assignable to type 'IdlField'.
                         Types of property 'type' are incompatible.
                           Type '{ definedWithTypeArgs: { name: "MerkleTreeSha256"; args: [{ value: "18"; }, { value: "20"; }]; }; }' is not assignable to type 'IdlType'.
       src/client.ts(223,9): error TS2322: Type 'Multisig' is not assignable to type 'Idl'.
       src/multisig.ts(65,50): error TS2345: Argument of type 'Multisig' is not assignable to parameter of type 'Idl'.
        ELIFECYCLE  Command failed with exit code 1.

The reason is that the following IDL types from Rust, introduced in #2011:

GenericLenArray(Box<IdlType>, String),
Generic(String),
DefinedWithTypeArgs {
name: String,
args: Vec<IdlDefinedTypeArg>,
},

are missing in ts/packages/anchor/src/idl.ts

vadorovsky added a commit to vadorovsky/anchor that referenced this issue Oct 28, 2023
The following new IDL types were introduced in coral-xyz#2011:

* `GenericLenArray`
* `Generic`
* `DefinedWithTypeArgs`

Usage of these types was leading to incompatibility of the IDL with
the TypeScript `IdlType`.

Fixes: coral-xyz#2687
vadorovsky added a commit to vadorovsky/anchor that referenced this issue Oct 28, 2023
The following new IDL types were introduced in coral-xyz#2011:

* `GenericLenArray`
* `Generic`
* `DefinedWithTypeArgs`

Usage of these types was leading to incompatibility of the IDL with
the TypeScript `IdlType`.

Fixes: coral-xyz#2687
@acheroncrypto acheroncrypto added ts idl related to the IDL, either program or client side labels Oct 28, 2023
@acheroncrypto acheroncrypto mentioned this issue Feb 25, 2024
@acheroncrypto
Copy link
Collaborator

Fixed by #2824.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idl related to the IDL, either program or client side ts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants