Похожие чаты

Hi, can someone help me with this? We have this

method call apiService that take some parameters and return an axios instance base on the 'method' that we pass, but i don't know how to tell typescript that the response of this method will be an AxiosResponse type, since it is not inferring it

8 ответов

9 просмотров
Isaac-. Автор вопроса

apiService is basically this

Isaac .
screenshot apiService is basically this

request initial value gets overwritten. Why do you need and instance here?

Isaac .
screenshot apiService is basically this

You may not need that switch statement at all. You can use axios() like in this example // Send a POST request axios({ method: 'post', url: '/user/12345', data: { firstName: 'Fred', lastName: 'Flintstone' } });

Isaac-. Автор вопроса
Andrey Piskunov
request initial value gets overwritten. Why do you...

i don't even know why are we using this apiService.js, it is a method that is been using all across all the project basically... in the configuration object, they extract a JSON Web token from the localStorage(something that i tried to change, but they do not want me to do it), and that is the main reason why i am force to use it :/

you could do something like if ((data in response) && (response.data?.status === 'ERROR'))...

Isaac .
screenshot apiService is basically this

What do you need that line with axios.create for if the variable gets overwritten?

Ts assumes that the apiService returns an instance, though it actually always returns promise, because that request variable gets overwritten

Isaac .
screenshot apiService is basically this

Well uhh, axios.create() doesn't create a request, so request should probably never be assigned to axios.create(). Here's how I would write that (assuming I'm still using switch): switch (meta.method) { case "POST": { return axios.post(url, meta.body, configuration); } case "PUT": { return axios.put(url, meta.body, configuration); } case "DELETE": { return axios.delete(url, configuration); } default: { return axios.get(url, configuration); } }

Похожие вопросы

Обсуждают сегодня

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
Привет)) уже кажется эту тему перемусолили, но вот я так и не понял. Я сейчас сижу на 27дюймов 2к мониторе. На Актуальной макоси, если я куплю 27д 4к монитор: - будет ли изобр...
Vladislav Piskunov
15
Hi guys, any problem with Pulsebrige? Trying to transfer from wETH to ETH. First it tells me to connect my metamask "through mobile app" not desktop. Then I did and confirmed ...
Snowflakecrypto
13
any reference of this implementation?
BitBuddha
29
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
&"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x64\dumpbin.exe" /EXPORTS C:\Users\Yeet\Tauon\vcpkg\installed\x64-window...
Martin Rys
6
Карта сайта