Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
Argument of type 'unknown' is not assignable to parameter of type 'string'. TS2345

I am running this code and have just seen this error appear.

import { ethers } from 'ethers'
import { getMulticallContract } from 'utils/contractHelpers'
import { MultiCallResponse } from './types'

export interface Call {
  address: string // Address of the contract
  name: string // Function name on the contract (example: balanceOf)
  params?: any[] // Function params
}

interface MulticallOptions {
  requireSuccess?: boolean
}

const multicall = async <T = any>(abi: any[], calls: Call[]): Promise<T> => {
  try {
    const multi = getMulticallContract()
    const itf = new ethers.utils.Interface(abi)

    const calldata = calls.map((call) => [call.address.toLowerCase(), itf.encodeFunctionData(call.name, call.params)])
    const { returnData } = await multi.aggregate(calldata)

    const res = returnData.map((call, i) => itf.decodeFunctionResult(calls[i].name, call))
    

    return res
  } catch (error) {
    throw new Error(error)
  }
}

This is the error that I'm getting, although until now this has been running just fine.

Argument of type 'unknown' is not assignable to parameter of type 'string'.  TS2345

    28 |     return res
    29 |   } catch (error) {
  > 30 |     throw new Error(error)
       |                     ^
    31 |   }
    32 | }
    33 |

I've looked through related questions, but can't see any exact solution in this case, but also I'm learning typescript currently.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

In the end I just added "useUnknownInCatchVariables": false, to tsconfig and it stopped errors from being converted to unknown, which is what was causing this issue.

I believe I have to upgrade typescript as well though, because there is a warning in tsconfig about this flag Unknown compiler option 'useUnknownInCatchVariables'.

Also see that another solution to this is mentioned in the docs: https://www.typescriptlang.org/tsconfig#useUnknownInCatchVariables

try {
  // ...
} catch (err) {
  // We have to verify err is an
  // error before using it as one.
  if (err instanceof Error) {
    console.log(err.message);
  }
}
about 4 years ago · Juan Pablo Isaza Report

0

In a case like this, you would never know what type of error will be going to be thrown(unknown), and new Error() receives a string

Based on the context of your multicall function, I would suggest that you put a meaningful string to that error (which production-grade web usually do)

You would throw something like this:

const multicall = async <T = any>(abi: any[], calls: Call[]): Promise<T> => {
  try {
    const multi = getMulticallContract();
    const itf = new ethers.utils.Interface(abi);

    const calldata = calls.map((call) => [
      call.address.toLowerCase(),
      itf.encodeFunctionData(call.name, call.params),
    ]);
    const { returnData } = await multi.aggregate(calldata);

    const res = returnData.map((call, i) => itf.decodeFunctionResult(calls[i].name, call));

    return res;
  } catch {
    throw new Error('something went wrong in the multical function');
  }
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!