ccxt icon indicating copy to clipboard operation
ccxt copied to clipboard

Typescript incorrect type

Open matvejs16 opened this issue 1 year ago • 10 comments

Operating System

Windows 11

Programming Languages

JavaScript

CCXT Version

4.4.14

Description

Type mismatch:

import { version, exchanges } from 'ccxt'; // exchanges is defined as type Record
console.log(version, exchanges); // in reality it's Array.

From example in README.md file:

import {version, exchanges} from 'ccxt';
console.log(version, Object.keys(exchanges));

Output:

4.4.14 [
  '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',  '8',  '9',
  '10', '11', '12', '13', '14', '15', '16', '17', '18', '19',
  '20', '21', '22', '23', '24', '25', '26', '27', '28', '29',
  '30', '31', '32', '33', '34', '35', '36', '37', '38', '39',
  '40', '41', '42', '43', '44', '45', '46', '47', '48', '49',
  '50', '51', '52', '53', '54', '55', '56', '57', '58', '59',
  '60', '61', '62', '63', '64', '65', '66', '67', '68', '69',
  '70', '71', '72', '73', '74', '75', '76', '77', '78', '79',
  '80', '81', '82', '83', '84', '85', '86', '87', '88', '89',
  '90', '91', '92', '93', '94', '95', '96', '97', '98', '99',
  ... 8 more items
]

If I remove Object.keys:

import { version, exchanges } from 'ccxt';
console.log(version, exchanges);

Output:

4.4.14 [
  'ace',              'alpaca',                'ascendex',
  'bequant',          'bigone',                'binance',
  'binancecoinm',     'binanceus',             'binanceusdm',
  'bingx',            'bit2c',                 'bitbank',
  'bitbns',           'bitcoincom',            'bitfinex',
  'bitfinex2',        'bitflyer',              'bitget',
  'bithumb',          'bitmart',               'bitmex',
  'bitopro',          'bitpanda',              'bitrue',
  'bitso',            'bitstamp',              'bitteam',
  'bitvavo',          'bl3p',                  'blockchaincom',
  'blofin',           'btcalpha',              'btcbox',
  'btcmarkets',       'btcturk',               'bybit',
  'cex',              'coinbase',              'coinbaseadvanced',
  'coinbaseexchange', 'coinbaseinternational', 'coincheck',
  'coinex',           'coinlist',              'coinmate',
  'coinmetro',        'coinone',               'coinsph',
  'coinspot',         'cryptocom',             'currencycom',
  'delta',            'deribit',               'digifinex',
  'exmo',             'fmfwio',                'gate',
  'gateio',           'gemini',                'hashkey',
  'hitbtc',           'hollaex',               'htx',
  'huobi',            'huobijp',               'hyperliquid',
  'idex',             'independentreserve',    'indodax',
  'kraken',           'krakenfutures',         'kucoin',
  'kucoinfutures',    'kuna',                  'latoken',
  'lbank',            'luno',                  'lykke',
  'mercado',          'mexc',                  'ndax',
  'novadax',          'oceanex',               'okcoin',
  'okx',              'onetrading',            'oxfun',
  'p2b',              'paradex',               'paymium',
  'phemex',           'poloniex',              'poloniexfutures',
  'probit',           'timex',                 'tokocrypto',
  'tradeogre',        'upbit',                 'vertex',
  'wavesexchange',
  ... 8 more items
]

Code

No code needed for this issue. All reproduction steps included in description

matvejs16 avatar Oct 07 '24 15:10 matvejs16

Hello @matvejs16, thanks for reporting it, yes it should be an array.

We will fix it shortly.

carlosmiei avatar Oct 07 '24 15:10 carlosmiei

Hello @matvejs16, thanks for reporting it, yes it should be an array.

We will fix it shortly.

Don't forget to fix it in example in README.md also

matvejs16 avatar Oct 07 '24 15:10 matvejs16

@matvejs16 Hum actually I was checking it and when imported like that exchanges is indeed a dictionary 🤔 image

carlosmiei avatar Oct 07 '24 15:10 carlosmiei

@matvejs16 if you import the entire object then yes it is a list image

carlosmiei avatar Oct 07 '24 15:10 carlosmiei

@carlosmiei I know where is problem, In my case I was using bundler, it uses commonjs, that's why I was getting different build files.

matvejs16 avatar Oct 07 '24 15:10 matvejs16

@matvejs16 But is everything sorted out now?

carlosmiei avatar Oct 07 '24 15:10 carlosmiei

@matvejs16 But is everything sorted out now?

I appreciate the follow-up, but this could still pose issues for developers using bundlers with CommonJS. The incorrect types might lead to subtle errors that developers may not anticipate.

I'd suggest either adjusting the types to unify the different import styles or at least adding a note in the documentation warning about potential issues with CommonJS and bundlers. This would help prevent confusion and ensure consistency across different environments.

matvejs16 avatar Oct 07 '24 15:10 matvejs16

@matvejs16 Yeah I agree, I will probably add a note to the docs to avoid introducing a breaking change since we have some users relying on exchanges as is.

carlosmiei avatar Oct 08 '24 08:10 carlosmiei

@matvejs16 Yeah I agree, I will probably add a note to the docs to avoid introducing a breaking change since we have some users relying on exchanges as is.

Thanks for looking into this issue, close this issue whenever you are ready and made changes in docs 🫡

matvejs16 avatar Oct 08 '24 12:10 matvejs16

@matvejs16 Yeah I agree, I will probably add a note to the docs to avoid introducing a breaking change since we have some users relying on exchanges as is.

Hey, I'm wondering, is it possible to get same result in commonJS as it's in here:

import { exchanges } from 'ccxt';

matvejs16 avatar Oct 19 '24 04:10 matvejs16