Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aws-lambda] Potentially incorrect API Gateway Proxy types? #69429

Open
ralbertazzi opened this issue Apr 24, 2024 · 1 comment
Open

[aws-lambda] Potentially incorrect API Gateway Proxy types? #69429

ralbertazzi opened this issue Apr 24, 2024 · 1 comment

Comments

@ralbertazzi
Copy link

ralbertazzi commented Apr 24, 2024

export interface APIGatewayProxyEventHeaders {
[name: string]: string | undefined;
}
export interface APIGatewayProxyEventMultiValueHeaders {
[name: string]: string[] | undefined;
}
export interface APIGatewayProxyEventPathParameters {
[name: string]: string | undefined;
}
export interface APIGatewayProxyEventQueryStringParameters {
[name: string]: string | undefined;
}
export interface APIGatewayProxyEventMultiValueQueryStringParameters {
[name: string]: string[] | undefined;
}
export interface APIGatewayProxyEventStageVariables {
[name: string]: string | undefined;
}

The current type definitions of the linked types assumes that a value can be present but have undefined value:

[name: string]: string | undefined

// the same as [name: string]: (string | undefined)

It feels weird that, for example, queryParameters can be present, have an actual entry, but have such value undefined. I wonder instead if the goal was to define such types differently, signaling that an event property can either be defined (and have all non-null values) or undefined

{ [name: string]: string } | undefined

Even better, since most of those types are then part of other Event types in the form of TheType | null or param? : TheType I would even be tempted to believe that this should be the correct type:

[name: string]: string

Let me know if you agree. If so, I'd gladly provide a pull request fixing it

@jelder
Copy link

jelder commented May 6, 2024

Agree that something is missing. This code for example requires the @ts-expect-error but also prints the query string.

export const connect: APIGatewayProxyWebsocketHandlerV2 = async (event) => {
  // @ts-expect-error queryStringParameters exists in reality
  console.log(JSON.stringify(event.queryStringParameters, null, 2))
  return {
    statusCode: 200,
    body: "connected",
  };
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants