Skip to content

Support for TypeScript by providing typings files #616

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

Merged
merged 37 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8d56e44
First partially working draft
lmammino Feb 20, 2021
85f03a8
Fixed typings for core
lmammino Feb 23, 2021
fb371e8
Merge branch 'release/2.x' of github.com:middyjs/middy into feature/t…
lmammino Feb 28, 2021
951aeaa
Added ts-standard and scaffolded tsd tests for every package
lmammino Feb 28, 2021
43d9937
Updated actions to use npm 7.5 and re-enabled typings test
lmammino Feb 28, 2021
161b5f6
Updated actions to use npm 7.5 and re-enabled typings test
lmammino Feb 28, 2021
1fa180b
removed typings-tester
lmammino Feb 28, 2021
e9a3600
Added typing tests for do-not-wait-for-empty-event-loop plus some pac…
lmammino Feb 28, 2021
fa91c8c
some other minor improvement in github actions
lmammino Feb 28, 2021
1254a4e
some small improvements
lmammino Mar 1, 2021
59794b1
Added typings for error-logger
lmammino Mar 1, 2021
9387635
Added typings in http-content-negotiation package
lmammino Mar 1, 2021
27d9fab
Added typings and typing tests for http-cors middleware
lmammino Mar 2, 2021
47c7bc2
Added typings and typings tests for http-error-handler
lmammino Mar 2, 2021
1398ae8
Added typings and typings tests for http-event-normalizer
lmammino Mar 2, 2021
4b2cf79
Added typings and typing tests for http-header-normalizer
lmammino Mar 2, 2021
ee7a287
Added typings and typing tests for http-json-body-parser
lmammino Mar 2, 2021
6a2632e
Added typings and typing tests for http-multipart-body-parser
lmammino Mar 2, 2021
6ea6f35
Added typings for http-partial-response
lmammino Mar 3, 2021
f55800d
Added typings for response-serializer
lmammino Mar 3, 2021
8ab5b90
Added typings for http-security-headers
lmammino Mar 3, 2021
74c4052
updated with latest changes from release/v2
lmammino Mar 3, 2021
f4aae18
Added typings and tests for http-urlencode-body-parser
lmammino Mar 6, 2021
0e1f3b5
Added typings for http-urlencode-path-parser
lmammino Mar 6, 2021
11ee670
Added typings for input-output-logger
lmammino Mar 6, 2021
9fcd9fb
Added typings for rds signer
lmammino Mar 6, 2021
0243cd5
Added typings for s3-key-normalizer
lmammino Mar 6, 2021
f696a09
Added typings for secrets-manager and updated typings for rds-signer
lmammino Mar 6, 2021
8929059
Added typings for sqs-json-body-parser
lmammino Mar 6, 2021
244bc8c
Added typings for sqs-partial-batch-failure
lmammino Mar 6, 2021
522b09b
Added typings for ssm package
lmammino Mar 7, 2021
109bd65
Using { new (): Type } rather than typeof Type
lmammino Mar 7, 2021
0074a30
Added typings for sts
lmammino Mar 7, 2021
e8e840c
Added typings to util and a number of fundamental refactorings for th…
lmammino Mar 7, 2021
0b6fbc5
Merge branch 'release/2.x' of github.com:middyjs/middy into feature/t…
lmammino Mar 12, 2021
78eaa75
Added cloudwatch metrics and validator typings
lmammino Mar 12, 2021
16390df
Updated TypeScript section in Readme
lmammino Mar 12, 2021
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
49 changes: 23 additions & 26 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,26 @@ jobs:
name: release
runs-on: ubuntu-latest
steps:
-
name: Checkout repository
uses: actions/checkout@master
-
name: Set up Node.js
uses: actions/setup-node@master
with:
node-version: 14.0.0
-
name: Create .npmrc
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
-
name: Install dependencies
run: |
npm install
-
name: Build as Commonjs for Node.js v12
run: |
./node_modules/.bin/lerna exec --bail --concurrency 2 -- babel --root-mode upward index.js --out-file index.js
-
name: Release
run: |
npm run lerna:publish
- name: Checkout repository
uses: actions/checkout@master
- name: Set up Node.js
uses: actions/setup-node@2
with:
node-version: 14.0.0
- name: Use npm 7.5
run: |
npm install -g npm@7.5
- name: Create .npmrc
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Install dependencies
run: |
npm install
- name: Build as Commonjs for Node.js v12
run: |
./node_modules/.bin/lerna exec --bail --concurrency 2 -- babel --root-mode upward index.js --out-file index.js
- name: Release
run: |
npm run lerna:publish
71 changes: 30 additions & 41 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
name: Tests

on:
pull_request:
branches:
- "**"
tags-ignore:
- '*.*.*'
push:
branches:
- "**"
tags-ignore:
- '*.*.*'
- "*.*.*"

jobs:

tests:
runs-on: ubuntu-latest

Expand All @@ -22,37 +16,32 @@ jobs:
node-version: [12.x, 14.x]

steps:
-
name: Checkout repository
uses: actions/checkout@v2
-
name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
-
name: Install dependencies
run: |
npm install
env:
CI: true
-
name: Linting
run: npm run test:lint:ci
env:
CI: true
-
name: Build as Commonjs for Node.js v12
run: |
./node_modules/.bin/lerna exec --bail --concurrency 2 -- babel --root-mode upward index.js --out-file index.js
-
name: Unit tests
run: npm run test:packages:unit
env:
CI: true
# Disabled until TS support has been updated.
# -
# name: Check typings
# run: npm run test:packages:typings
# env:
# CI: true
- name: Checkout repository
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Use npm 7.5
run: |
npm install -g npm@7.5
- name: Install dependencies
run: |
npm install
env:
CI: true
- name: Linting
run: npm run test:lint:ci
env:
CI: true
- name: Build as Commonjs for Node.js v12
run: |
./node_modules/.bin/lerna exec --bail --concurrency 2 -- babel --root-mode upward index.js --out-file index.js
- name: Unit tests
run: npm run test:packages:unit
env:
CI: true
- name: Check typings
run: npm run test:packages:typings
env:
CI: true
29 changes: 28 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,35 @@ module.exports = (opts = {}) => {

Check the [code for existing middlewares](/packages) to see more examples on how to write a middleware.


## TypeScript
See [#589 TypeScript Support](https://github.com/middyjs/middy/issues/589)

Middy can be used with TypeScript with typings built in in every official package.

Here's an example of how you might be using Middy with TypeScript for a Lambda receiving events from API Gateway:

```typescript
import middy from '@middy/core'
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'

async function baseHandler (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> {
// the returned response will be checked against the type `APIGatewayProxyResult`
return {
statusCode: 200,
body: `Hello from ${event.path}`
}
}

let handler = middy(baseHandler)
handler
.use(someMiddleware)
.use(someOtherMiddleware)

export default handler
```

**Note**: the Middy core team does not use TypeScript often and we can't certainly claim that we are TypeScript experts. We tried our best to come up
with type definitions that should give TypeScript users a good experience. There is certainly room for improvement, so we would be more than happy to receive contributions 😊


## Common Patterns and Best Practice
Expand Down
Loading