title: How to type this middleware function on aws lambda?
body: <p>I have this middleware that gets the aws lambda function <code>event</code>:</p>
  <pre><code>export function hasuraActionHandler&lt;Input, Output&gt;(
    allowedRoles: string[],
    handler: (
      input: Input,
      hasuraRole: string,
      hasuraUserId?: string,
      ipAddress?: string,
      // @ts-ignore
      context: Context,
    ) =&gt; Promise&lt;typeof formatJSONResponse&lt;Output&gt;&gt;
  ) :any {
    return async (event, context, callback) =&gt; {
      const { hasuraRole, hasuraUserId, input, ipAddress } =
        getHasuraActionParams&lt;Input&gt;(event);
  
      if (!allowedRoles.includes(hasuraRole)) {
        return callback(null, {
          statusCode: 403,
          body: JSON.stringify({
            message: 'Forbidden',
          }),
        });
      }
  
      try {
        callback(null, {
          statusCode: 200,
          body: await handler(input, hasuraRole, hasuraUserId, ipAddress, context),
        });
      } catch (e) {
        console.error(e);
  
        return callback(null, {
          statusCode: 400,
          body: JSON.stringify({
            message: e
          }),
        });
      }
    };
  }
  
  </code></pre>
  <p><code>getHasuraActionParams</code> function:</p>
  <pre><code>export function getHasuraEventParams&lt;T&gt;(event: APIGatewayEvent): {
    data: T;
    hasuraRole: string;
    hasuraAllowedRoles?: string[];
    hasuraUserId?: string;
  } {
    const data = parse(event.body).event.data
    const {
      &quot;x-hasura-allowed-roles&quot;: hasuraAllowedRoles,
      &quot;x-hasura-role&quot;: hasuraRole,
      &quot;x-hasura-user-id&quot;: hasuraUserId
    } = parse(event.body).event.session_variables;
    return { data, hasuraRole, hasuraAllowedRoles, hasuraUserId };
  }
  
  </code></pre>
  <p>the aws function:</p>
  <pre><code>const ban_account = hasuraActionHandler&lt;ban_accountArgs, ban_account_output&gt;(
    [&quot;admin&quot;],
    async (input, hasuraRole, hasuraUserId, context) =&gt; {
      
      .... 
  
      return formatJSONResponse({
        id: &quot;1&quot;
      });
    }
  );
  </code></pre>
  <p>ban_account_output type:</p>
  <pre><code>type ban_account_output = {
    id: string;
  };
  
  </code></pre>
  <p>the formatJSONResponse function:</p>
  <pre><code>export const formatJSONResponse = (response: Record&lt;string, unknown&gt;) =&gt; {
    return {
      statusCode: 200,
      body: JSON.stringify(response)
    };
  };
  
  </code></pre>
  <p>Question is, how to type the <code>Promise&lt;typeof formatJSONResponse&lt;Output&gt;</code> in the middleware? As is it throws this: <code>TS2635: Type '(response: Record ) =&gt; { statusCode: number; body: string; }' has no signatures for which the type argument list is applicable.</code></p>
  <p>Is it also possible to type the <code>:any</code> on the middleware?</p>
  <p>codesandbox: <a href="https://codesandbox.io/s/lingering-pond-wcu8go?file=/src/index.ts" rel="nofollow noreferrer">https://codesandbox.io/s/lingering-pond-wcu8go?file=/src/index.ts</a></p>