Skip to content

error Unsafe argument of type any[] assigned to a parameter of type Type<any>[] #549

Open
@peterpeterparker

Description

@peterpeterparker

Issue

TypeScript types description for init function generated by Candid are not descriptive or generic enough to comply with linters.

For example, the generated types of the ICP ledger:

export declare const init: (args: {IDL: typeof IDL}) => IDL.Type[];

Have to be implemented as following:

const initArgs: InitArgs = {
      send_whitelist: [],
      token_symbol: ['ICP'],
      transfer_fee: [{e8s: 10_000n}],
      minting_account: minterAccountIdentifier,
      maximum_number_of_accounts: [],
      accounts_overflow_trim_quantity: [],
      transaction_window: [],
      max_message_size_bytes: [],
      icrc1_minting_account: [],
      archive_options: [],
      initial_values: [[ledgerAccountIdentifier, {e8s: 100_000_000_000n}]],
      token_name: ['Internet Computer'],
      feature_flags: []
    };

    const upgradeArgs = [];

    const arg = IDL.encode(init({IDL}), {Init: initArgs});

But lead to following linter error when examinated by eslint:

52:28 error Unsafe argument of type any[] assigned to a parameter of type Type<any>[] @typescript-eslint/no-unsafe-argument

(line 52 being the encode(init...) usage)

Liwise, my editor complains as well:

Capture d’écran 2024-05-12 à 21 24 51

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions