[koa] Allow augmenting ContextDelegatedRequest/Response#74991
[koa] Allow augmenting ContextDelegatedRequest/Response#74991unrevised6419 wants to merge 1 commit into
Conversation
48aa7fa to
e6e09d2
Compare
fdca105 to
598afd2
Compare
598afd2 to
3799d17
Compare
|
@unrevised6419 Thank you for submitting this PR! This is a live comment that I will keep updated. 1 package in this PRCode ReviewsBecause 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
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": "2f65eefff7ae35634d34386f7184a7b1d667d4a3",
"mergeBaseOid": "ca06abb4cc3399ea070c122be329a22f1c3b6800",
"lastPushDate": "2026-05-12T19:20:02.000Z",
"lastActivityDate": "2026-05-16T08:14:52.000Z",
"hasMergeConflict": false,
"isFirstContribution": false,
"tooManyFiles": false,
"hugeChange": false,
"tooManyCommits": false,
"tooManyReviews": false,
"popularityLevel": "Critical",
"pkgInfo": [
{
"name": "koa",
"kind": "edit",
"files": [
{
"path": "types/koa/index.d.ts",
"kind": "definition"
},
{
"path": "types/koa/test/augment-delegated.ts",
"kind": "test"
},
{
"path": "types/koa/tsconfig.json",
"kind": "package-meta-ok"
},
{
"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"
} |
|
🔔 @jkeylu @brikou @harryparkdotio @chatoo2412 @tellnes @pkuczynski @vnoder — please review this PR in the next few days. Be sure to explicitly select |
|
Wait, is this why you brought back v2? It seems weird to do this to v2 and not to later versions? |
yes
I mentioned this in the PR description as a follow-up. I did it in the same PR. |
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.
3799d17 to
2f65eef
Compare
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
BaseContextextendsContextDelegatedRequestandContextDelegatedResponsedirectly, andBaseRequest/BaseResponseextend 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
ContextDelegatedResponsewith custom delegated methods. The augmentation accidentally wiped out the original delegated members instead of adding to them.What
declare namespace Application:DefaultContextDelegatedRequest extends ContextDelegatedRequestDefaultContextDelegatedResponse extends ContextDelegatedResponseBaseRequest,BaseResponse, andBaseContextat the newDefault*interfaces.Naming mirrors the existing
DefaultState/DefaultContextpattern 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 (Applied in the same PR./types/koa) in a separate PR — same problem exists there.Test plan
Koa.DefaultContextDelegatedResponseadds members toBaseContextwithout erasing the originals.