Skip to content
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

Clean up cookie creation #381

Merged
merged 4 commits into from
Mar 14, 2024
Merged

Clean up cookie creation #381

merged 4 commits into from
Mar 14, 2024

Conversation

wjhsf
Copy link
Contributor

@wjhsf wjhsf commented Mar 13, 2024

Currently, the props on Cookie all have | undefined, even though none of them actually ever use undefined as a value. If we get rid of | undefined, though, we get a TypeScript error complaining that the prop is not definitively assigned in the constructor. This is because we use Object.assign to initialize props, and I guess TypeScript just can't quite handle that. So, to get rid of undefined as a false possible value, we have to manually assign every prop. A bit more verbose, but not a significant change.

Additionally, the cookie constructor options are identical to the props of Cookie, excluding the methods, so I changed the type from explicitly listing everything to just a mapped type, for simpler maintenance. I wasn't sure if that would be a good idea, because sometimes mapped types get mangled, but the result type is still readable, so I think it's fine.

screenshot of the computed CreateCookieOptions type, showing that it is reported as a simple, readable key/value object type, rather than a hard-to-understand layering of mapped types

nb: This was originally part of #377, but has been split out for easier review.

@wjhsf wjhsf merged commit b775575 into master Mar 14, 2024
6 checks passed
@wjhsf wjhsf deleted the cleaner-cookie-creation branch March 14, 2024 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants