Skip to content

Commit f955629

Browse files
authored
improve typescript instrucitons
1 parent 42d3c35 commit f955629

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ This will start the normal create-react-app dev server and open your app at `htt
5050

5151
Local in-app requests to the relative path `/.netlify/functions/*` will automatically be proxied to the local functions dev server.
5252

53+
## Typescript
54+
5355
<details>
5456
<summary>
55-
<b id="typescript">Typescript</b>
57+
<b id="typescript">Click for instructions</b>
5658
</summary>
5759
You can use Typescript in both your React code (with `react-scripts` v2.1+) and your lambda functions )with `netlify-lambda` v1.1+). Follow these instructions:
5860

@@ -61,18 +63,24 @@ You can use Typescript in both your React code (with `react-scripts` v2.1+) and
6163
3. use types in your event handler:
6264

6365
```ts
64-
import { Handler, Context, Callback } from 'aws-lambda';
66+
import { Handler, Context, Callback, APIGatewayEvent } from 'aws-lambda';
6567

6668
interface HelloResponse {
6769
statusCode: number;
6870
body: string;
6971
}
7072

71-
const handler: Handler = (event: any, context: Context, callback: Callback) => {
73+
const handler: Handler = (
74+
event: APIGatewayEvent,
75+
context: Context,
76+
callback: Callback
77+
) => {
78+
const params = event.queryStringParameters;
7279
const response: HelloResponse = {
7380
statusCode: 200,
7481
body: JSON.stringify({
75-
msg: `Hello world ${Math.floor(Math.random() * 10)}`
82+
msg: `Hello world ${Math.floor(Math.random() * 10)}`,
83+
params
7684
})
7785
};
7886

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy