Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

97
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda