fix(http): getCookies returns Partial<Record<string, string>> (closes #7053)#7131
Open
MukundaKatta wants to merge 1 commit intodenoland:mainfrom
Open
fix(http): getCookies returns Partial<Record<string, string>> (closes #7053)#7131MukundaKatta wants to merge 1 commit intodenoland:mainfrom
MukundaKatta wants to merge 1 commit intodenoland:mainfrom
Conversation
…enoland#7053) The previous return type `Record<string, string>` was a lie: arbitrary key access can yield `undefined` because the function only populates keys present in the Cookie header. Consumers without `noUncheckedIndexedAccess` enabled would unsafely treat missing-cookie reads as guaranteed strings. Switch to `Partial<Record<string, string>>`. The runtime behavior is unchanged (the returned object is still null-prototyped, so missing-key access really does yield `undefined` rather than an inherited Object prototype method), but TypeScript now reflects that. - update return type + JSDoc to spell out the contract - regression test asserts the new exact type via IsExact<> - keeps the existing null-prototype check so behaviour stays pinned
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7131 +/- ##
=======================================
Coverage 94.61% 94.61%
=======================================
Files 634 634
Lines 51801 51802 +1
Branches 9329 9329
=======================================
+ Hits 49011 49012 +1
Misses 2216 2216
Partials 574 574 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Closes #7053 (and the runtime/TS gap originally tracked in #6852).
What's wrong
The previous return type
Record<string, string>told TypeScript that any key access yielded astring, but the function only populates keys present in theCookieheader. Consumers withoutnoUncheckedIndexedAccessenabled would unsafely treat missing-cookie reads as guaranteed strings:Fix
Return type is now
Partial<Record<string, string>>. Runtime behaviour is unchanged (the returned object is still null-prototyped, so missing-key access really does yieldundefinedrather than an inheritedObject.prototypemethod), but TypeScript now reflects that.What changed
getCookiesreturn type:Record<string, string>→Partial<Record<string, string>>string | undefinedaccess semantics)IsExact<>so a future revert can't sneak pastTest plan
deno test http/cookie_test.ts— 10/10 passing locally with full type-checkWhy now
#7053 explicitly notes the previous attempt left this "still" wrong — the type and the runtime were out of sync.