Похожие чаты

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 ответов

5 просмотров
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); } }

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

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

Какой-то там пердун в 90-х решил, что есть какая-то разная типизация. Кого вообще это волнует?
КТ315
49
Hi. Do we have a raid bot? Why nobody doing raids on X? Even RH mentioned this and nobody paying attention...whats the channel for hex memes? If mods cant run raids just insta...
H
31
Подскажите, а есть vault lite или ченить такое?) А то нужен вольт для похода в вольт, но весит он ~500 мб) как-то многовато для парочки запросов ))
Alexandr Orloff
17
блеать, почему так?? где в роутере это исправляется?
Арсен Маньяков 🇦🇲
16
void terminal_scroll() { memmove(terminal_buffer, terminal_buffer + VGA_WIDTH, buffer_size - VGA_WIDTH); memset(terminal_buffer + buffer_size - VGA_WIDTH, 0, VGA_WIDTH); ...
Егор
47
🌊 Ocean Nodes Dashboard Update 🚀 Hey, Oceaners! First off, a massive round of applause 👏to all of you for the amazing engagement since we launched Ocean Nodes. In just a few ...
KreigDK | Never DM first🌊
3
Всем привет! Подскажите, пожалуйста, в чем ошибка? Настраиваю подключение к MySQL. Либы лежат рядом с exe. Все как по "учебнику"
Евгений
16
А можете как-то проверить меня по знаниям по ассемблеру?
A A
132
Здравствуйте! У меня появилась возможность купить книгу "Изучай Haskell во имя добра!". Но я где-то слышал, что эта книга устарела. Насколько это правда??
E
22
люди, которые используют flameshot, к вам вопрос. Можно-ли поставить хоткей на создание скриншота? В программе есть отдел "горячие клавиши", но там все для редактирования, скр...
ThunDer104
11
Карта сайта