Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Проблема с дженериками (https://javascript.ru/forum/misc/83283-problema-s-dzhenerikami.html)

FlyTen 09.11.2021 01:17

Проблема с дженериками
 
Добрый вечер ,
проблема с дженереками .

export interface Location {
  id: number;
  address: {
    houseNumber: string;
  };
}
export const getEuropeLocations = async (
  apiKey: string
): Promise<Locations> => {
  let response = await axios({
    method: "get",
    url: `${apiBaseUrl}europe/`,
    headers: {
      Authorization: `Bearer ${apiKey}`,
    },
  });
  return response.data as Locations;
};



Пытаюсь сделать из getEuropeLocations используя generics :

export const getEuropeLocations = async (
  apiKey: string
) => {
  let response = await axios.get<Location>({
    method: "get",
    url: `${apiBaseUrl}europe/`,
    headers: {
      Authorization: `Bearer ${apiKey}`,
    },
  });
  return response.data;
};


в чем моя ошибка?

Aetae 14.11.2021 01:32

А в чём твоя проблема?)

MallSerg 14.11.2021 03:15

Цитата:

в чем моя ошибка?
В лишней букве?
В том что форум JavaScript а вопрос по TypeScript?

Aetae 14.11.2021 04:21

MallSerg, ну второе точно не ошибка: TS не самостоятельный язык, а всего лишь диалект.)


Часовой пояс GMT +3, время: 22:07.