Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ app.get('/todos', async () => {
});

app.post('/todos', async ({ req }) => {
const body = await req.json();
const body = (await req.json()) as { title: string };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind having these in the snippets, but I'm mildly concerned about the implications that these new types have on end customers.

Does this mean customers who use the library now have to do this cast every time they use this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good point, there will be effects on customer. If you are doing stuff like req.json() in middleware or a handler like in this example, you would need to fix the types with a cast now that you are not getting Promise<any> back. I'm not sure that's a bad thing though, because it makes clear that you are handling untrusted data. Ultimately if you want real safety guarantees you should really be using a validation library like Zod and this problem goes away. That said, this does feel quite disruptive so I'm open to persuasion that we should leave things as they are.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me take it for a spin and see how it works in practice before I insist further in either way.

const todo = await createTodo(body.title);

return new Response(JSON.stringify(todo), {
Expand Down
4 changes: 3 additions & 1 deletion examples/snippets/parameters/customProviderVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class HashiCorpVaultProvider extends BaseProvider {
if (!res.ok) {
throw new GetParameterError(`Failed to fetch secret ${res.statusText}`);
}
const response = await res.json();
const response = (await res.json()) as {
data: { data: Record<string, unknown> };
};
return response.data.data;
}

Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"typedoc": "^0.28.19",
"typedoc-plugin-missing-exports": "^4.1.3",
"typescript": "^6.0.3",
"undici-types": "^7.24.6",
Comment thread
dreamorosi marked this conversation as resolved.
"vitest": "^4.1.2"
},
"lint-staged": {
Expand Down
1 change: 1 addition & 0 deletions packages/event-handler/src/http/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
APIGatewayProxyResult,
APIGatewayProxyStructuredResultV2,
} from 'aws-lambda';
import type { BodyInit } from 'undici-types';
import type {
ExtendedAPIGatewayProxyResult,
ExtendedAPIGatewayProxyResultBody,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSONValue } from '@aws-lambda-powertools/commons/types';
import { Router } from '@aws-lambda-powertools/event-handler/http';
import type { Context } from 'aws-lambda';
import { binaryRouter } from './routers/binaryRouter.js';
Expand Down Expand Up @@ -27,7 +28,7 @@ const app = new Router()

// Request body parsing and headers
app.post('/echo', async ({ req }) => {
const body = await req.json();
const body = (await req.json()) as JSONValue;
const contentType = req.headers.get('content-type');
const customHeader = req.headers.get('x-custom-header');
const multiHeader = req.headers.get('x-multi-header');
Expand Down
Loading
Loading