Search code examples
flowtype

How do you read this in Flow?


Im new to a codebase where they use flow.

I dont understand this bit:

const {
  headers: { location },
}: Response = await httpClient.post(getChangeServicesUrl(userId), newChangeService);

Can you please explain whats happening?

is it, destructuring location, and then whats the colon doing?

thanks


Solution

  • const {
      headers: { location },
    }: Response = await httpClient.post(...
    

    Is equivalent to:

    const response: Response = await httpClient.post(...
    const location = response.headers.location;
    

    So first part is object destructuring

    const {
      headers: { location },
    }
    

    And : Response is a type annotation