Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

fix(hooks): match type of Config.runHook to IConfig.runHook #158

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export class Config implements IConfig {
}
}

async runHook<T>(event: string, opts: T) {
async runHook<T extends Hooks, K extends Extract<keyof T, string>>(event: K, opts: T[K]): Promise<void> {
debug('start %s hook', event)
const promises = this.plugins.map(p => {
const debug = require('debug')([this.bin, p.name, 'hooks', event].join(':'))
Expand Down
3 changes: 1 addition & 2 deletions test/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ describe('typescript', () => {
withConfig
.stdout()
.it('runs init hook', async ctx => {
// to-do: fix union types
await (ctx.config.runHook as any)('init', {id: 'myid', argv: ['foo']})
await (ctx.config.runHook)('init', {id: 'myid', argv: ['foo']})
expect(ctx.stdout).to.equal('running ts init hook\n')
})
})