Skip to content

Commit 9716bc5

Browse files
committed
feat(plugin-koa): Add complete types
1 parent d0843d3 commit 9716bc5

File tree

4 files changed

+162
-1
lines changed

4 files changed

+162
-1
lines changed

packages/plugin-koa/package-lock.json

Lines changed: 139 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/plugin-koa/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@bugsnag/js": "*"
3030
},
3131
"devDependencies": {
32+
"@types/koa": "^2.11.3",
3233
"jasmine": "^3.1.0",
3334
"nyc": "^12.0.2"
3435
},
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1-
import { Plugin } from '@bugsnag/node'
1+
import { Client, Plugin } from '@bugsnag/core'
2+
import * as Koa from 'koa'
23
declare const bugsnagPluginKoa: Plugin
34
export default bugsnagPluginKoa
5+
6+
interface BugsnagPluginKoaResult {
7+
errorHandler: (err: Error, ctx: Koa.Context) => void
8+
requestHandler: Koa.Middleware
9+
}
10+
11+
// add a new call signature for the getPlugin() method that types the plugin result
12+
declare module '@bugsnag/core' {
13+
interface Client {
14+
getPlugin(id: 'koa'): BugsnagPluginKoaResult | undefined
15+
}
16+
}
17+
18+
// define ctx.bugsnag for koa middleware by declaration merging
19+
declare module 'koa' {
20+
interface BaseContext {
21+
bugsnag?: Client
22+
}
23+
}

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,6 @@
6969
"packages/plugin-react",
7070
"packages/plugin-vue",
7171
"packages/plugin-express",
72+
"packages/plugin-koa",
7273
]
7374
}

0 commit comments

Comments
 (0)