0
votes

How to assign a correct type to remove the error??? I've tried different solutions but always I get a different type of error. This one is the most understandable.

Here it is Typescript Error Message:

error TS2345: Argument of type '([currency, data]: [string, { available: string;}]) => void' is not assignable to parameter of type '(value: [string, { avaiable: string; }], index: number, array: [string, { avaiable: string; }][]) => void'. Types of parameters '__0' and 'value' are incompatible. Type '[string, { avaiable: string; }]' is not assignable to type '[string, { available: string; }]'. Property 'available' is missing in type '{ avaiable: string; }' but required in type '{ available: string; }'.

interface Balances {
  [key: string]: { avaiable: string };
}

binance.balance(async (error: any, balances: Balances) => {
        Object.entries(balances).map(
          ([currency, data]: [string, { available: string }]) => {
            console.log(data.available);
            console.log(currency)
          }
        );
      }
1

1 Answers

1
votes

You can safely remove the redundant types on the map as they are inferred.

const yourFunc = async (error: any, balances: Balances) => {
    return Object.entries(balances).map(
      ([currency, data]) => {
        console.log(data.avaiable);
        console.log(currency)
      }
    );
  }

Furthermore, you have a typo in avaiable in the interface declaration.