TS7044

error TS7044: Parameter ‘response‘ implicitly has an ‘any’ type, but a better type may be inferred from usage.

Broken Code ❌

1
2
3
4
5
6
7
8
9
import api from 'api';

const sdk = api('@coinbase-exchange/v1.0#qgumw1pl3iz4yut');

sdk['ExchangeRESTAPI_GetProductTrades']({
product_id: 'BTC-USD'
}).then((response) => {
console.log(`Found "${response.length}" trades.`);
});

Fixed Code ✔️

When a library returns an ‘any‘ type, then it is worth setting a type explicitly yourself if you know the return value type:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import api from 'api';

const sdk = api('@coinbase-exchange/v1.0#qgumw1pl3iz4yut');

sdk['ExchangeRESTAPI_GetProductTrades']({
product_id: 'BTC-USD'
}).then((response: Array<{
price: string,
side: 'buy' | 'sell',
size: string,
time: string,
trade_id: number
}>) => {
console.log(`Found "${response.length}" trades.`);
});