Skip to content

[koa/v2] Allow augmenting ContextDelegatedRequest/Response#74991

Open
unrevised6419 wants to merge 1 commit into
DefinitelyTyped:masterfrom
unrevised6419:koa-v2-augment-context-delegated
Open

[koa/v2] Allow augmenting ContextDelegatedRequest/Response#74991
unrevised6419 wants to merge 1 commit into
DefinitelyTyped:masterfrom
unrevised6419:koa-v2-augment-context-delegated

Conversation

@unrevised6419
Copy link
Copy Markdown
Contributor

@unrevised6419 unrevised6419 commented May 12, 2026

Stacked on top of #74990 ([koa] Add v2 types). Should be reviewed/merged after that PR; until then the diff here will include the v2 add commit.

Why

Koa v2's BaseContext extends ContextDelegatedRequest and ContextDelegatedResponse directly, and BaseRequest/BaseResponse extend those same interfaces. Because the original interface names aren't re-declared anywhere that's open for augmentation, consumers can't extend the delegated members through declaration merging — attempting to do so silently overrides the original interface instead.

Real-world example: strapi/strapi#25424 tried to extend ContextDelegatedResponse with custom delegated methods. The augmentation accidentally wiped out the original delegated members instead of adding to them.

What

  • Add two empty marker interfaces inside declare namespace Application:
    • DefaultContextDelegatedRequest extends ContextDelegatedRequest
    • DefaultContextDelegatedResponse extends ContextDelegatedResponse
  • Point BaseRequest, BaseResponse, and BaseContext at the new Default* interfaces.

Naming mirrors the existing DefaultState / DefaultContext pattern already in this file, giving consumers a stable, augmentation-friendly seam for the delegated request and response shapes without changing the public API for existing users.

Follow-up

If reviewers want, happy to apply the same augmentation seam to koa v3 (./types/koa) in a separate PR — same problem exists there.

Test plan

  • Existing koa v2 tests still pass (no behavioral change to default types).
  • Declaration-merging Koa.DefaultContextDelegatedResponse adds members to BaseContext without erasing the originals.

@typescript-bot typescript-bot moved this to Needs Author Action in Pull Request Status Board May 12, 2026
@unrevised6419 unrevised6419 force-pushed the koa-v2-augment-context-delegated branch from 48aa7fa to e6e09d2 Compare May 12, 2026 19:39
@unrevised6419 unrevised6419 force-pushed the koa-v2-augment-context-delegated branch 3 times, most recently from fdca105 to 598afd2 Compare May 14, 2026 09:58
@unrevised6419 unrevised6419 mentioned this pull request May 14, 2026
8 tasks
@unrevised6419 unrevised6419 changed the title [koa] Allow augmenting ContextDelegatedRequest/Response [koa/v2] Allow augmenting ContextDelegatedRequest/Response May 14, 2026
Expose `DefaultContextDelegatedRequest` and `DefaultContextDelegatedResponse`
empty marker interfaces — mirroring the existing `DefaultState` /
`DefaultContext` pattern — so consumers can extend the delegated
request/response shapes (and thereby `BaseContext`) via declaration
merging without having to override the original interfaces.

Add a dedicated test exercising the new augmentation seam and asserting
that the original delegated members (`redirect`, `attachment`, `header`,
`method`, …) remain in place after merging.
@unrevised6419 unrevised6419 force-pushed the koa-v2-augment-context-delegated branch from 598afd2 to 3799d17 Compare May 14, 2026 20:23
@unrevised6419 unrevised6419 marked this pull request as ready for review May 14, 2026 20:23
@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented May 14, 2026

@unrevised6419 Thank you for submitting this PR!

This is a live comment that I will keep updated.

1 package in this PR

Code Reviews

Because this is a widely-used package, a DT maintainer will need to review it before it can be merged.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • 🕐 Most recent commit is approved by a DT maintainer

Once every item on this list is checked, I'll ask you for permission to merge and publish the changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 74991,
  "author": "unrevised6419",
  "headCommitOid": "3799d175131c2a415030f803bd98a0bdd08dec20",
  "mergeBaseOid": "3c8407903130ad6ac2dca5af44bffc0ffad64d6e",
  "lastPushDate": "2026-05-12T19:20:02.000Z",
  "lastActivityDate": "2026-05-14T20:23:51.000Z",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "tooManyCommits": false,
  "tooManyReviews": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "koa",
      "kind": "edit",
      "files": [
        {
          "path": "types/koa/v2/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/koa/v2/test/augment-delegated.ts",
          "kind": "test"
        },
        {
          "path": "types/koa/v2/tsconfig.json",
          "kind": "package-meta-ok"
        }
      ],
      "owners": [
        "jkeylu",
        "brikou",
        "harryparkdotio",
        "chatoo2412",
        "tellnes",
        "pkuczynski",
        "vnoder"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [],
  "mainBotCommentID": 4454443407,
  "ciResult": "pass"
}

@typescript-bot
Copy link
Copy Markdown
Contributor

🔔 @jkeylu @brikou @harryparkdotio @chatoo2412 @tellnes @pkuczynski @vnoder — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

@typescript-bot typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in Pull Request Status Board May 14, 2026
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in Pull Request Status Board May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Needs Maintainer Review

Development

Successfully merging this pull request may close these issues.

2 participants