Skip to content

Widen onTeardown callback return type to () => unknown | Promise<unknown> #21

@jbrecht

Description

@jbrecht

Problem

StepContext.onTeardown is typed (fn: () => void | Promise<void>) => void. The natural cleanup one-liner doesn't typecheck:

ctx.onTeardown(() => Promise.all(people.map((p) => deletePerson(p.id))))
//             ^ Type 'Promise<void[]>' is not assignable to 'void | Promise<void>'

So you have to wrap it just to discard the resolved array:

ctx.onTeardown(async () => {
  await Promise.all(people.map((p) => deletePerson(p.id)))
})

Suggested direction

Widen the callback return type to () => unknown | Promise<unknown> (the result is awaited and discarded anyway). Same papercut applies anywhere a teardown thunk is accepted. Tiny DX win — Promise.all(...) and other value-returning cleanups just work.

Minor follow-up to #8.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions