'How to use google places autocomplete api with typescript?

I'm using typescript/react and calling my own backend proxy to google maps autocomplete api, and I'm wondering how I can handle the response data with TS types.

For example, from my react code I have this method..

  static async autocomplete(input: string): Promise<THE RESPONSE SHAPE> {
    const res: AxiosResponse<THE RESPONSE SHAPE> = await axios.get(
      '/api/places/autocomplete/' + input
    );

    return res.data;
  }

Is there some way that I can avoid using <any> and get only the autocomplete response shape in typescript?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source