[koa/v2] Allow augmenting ContextDelegatedRequest/Response#74991
Open
unrevised6419 wants to merge 1 commit into
Open
[koa/v2] Allow augmenting ContextDelegatedRequest/Response#74991unrevised6419 wants to merge 1 commit into
unrevised6419 wants to merge 1 commit into
Conversation
48aa7fa to
e6e09d2
Compare
fdca105 to
598afd2
Compare
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.
598afd2 to
3799d17
Compare
Contributor
|
@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": "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"
} |
Contributor
|
🔔 @jkeylu @brikou @harryparkdotio @chatoo2412 @tellnes @pkuczynski @vnoder — please review this PR in the next few days. Be sure to explicitly select |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (
./types/koa) in a separate PR — same problem exists there.Test plan
Koa.DefaultContextDelegatedResponseadds members toBaseContextwithout erasing the originals.