-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
types: fix misleading Headers type definition #1611
Conversation
I think it's better to rely on TypeScript's compiler flags for this. People who want to have this level of strictness should probably enable this flag: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html#checked-indexed-accesses---nouncheckedindexedaccess |
It would seem so, but then it'll be enabled for the whole project and might have unintended consequences for other types, as well as array indexing and such. Not really sure what's the best approach usually is, but I feel that baking it to kit's types itself would be better so general TS or even JSDoc users would get that type safety out of the box. |
Would we also need to say that |
Not really, that shouldn't be the case at all. All of those mentioned can (now, thanks to #1447) be typed by the user, with the exception of Also, the request headers do actually returns Additional context from #1369 where it's necessary to guard endpoint output with This would also be a nice preliminary for the upcoming |
After some thought I think I'm now in favor of this change. If some headers could be set (property exists on the object) but be |
Personally I wouldn't do it, this is an opt-in feature for codebases via the |
What about object with actual |
If headers can look like {
foo: 'hi',
bar: undefined
} Then I think it's probably better to explicitely type it that way. There's a difference between something not being defined as a property and something being defined as a property which is set to |
That is indeed the case I encountered, this is an actual headers I received (a production app, and not just once) in the log {
authorization: undefined,
cookie: undefined
} It might be cached from previous requests/responses, but nonetheless, it still sends those through handle and endpoints. |
I'm surprised by
Where would that be coming from? If it's something internal, then I think maybe I'd rather change that because it's a weird thing to get. Like at that point you could list all possible headers with |
🦋 Changeset detectedLatest commit: b8d7819 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I can't pinpoint it enough to the internal stuff, but here's where it's coming from and what I think is happening. The application sets (and removes) the My guess is that it was cached even after the user logs out (cookie removed and no fetch calls with authorization header). I haven't tested it again, but if my guess is correct, any arbitrary headers that's returned from an endpoint or passed with a fetch call would also show up in |
Hmm, this is a tough one. But since I don't think it can come from a browser request and only from the developer's own endpoint and because we have |
Currently,
Headers
is set such that its value will always be astring
, which gives the assumption that it will always exists even if it's just an empty string. But, this is not the case, especially when one is checking for cookies inrequest.headers.cookie
, in which it can beundefined
and the same applies to other headers.Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts