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)
}
);
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.