-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Typing of ServerResponse doesn't jive with possibly undefined cookies (TypeScript) #1369
Typing of ServerResponse doesn't jive with possibly undefined cookies (TypeScript) #1369
Comments
Do you have a repo showing this issue? I can't reproduce it at all, and I don't understand why TS is giving you that error |
This snippet should do it, put in any endpoint file import type { RequestHandler } from '@sveltejs/kit';
export const get: RequestHandler = async ({ body }) => {
if (body) {
return {
headers: {
location: '/logout',
},
};
} else {
return {
headers: {
location: '/auth/farewell',
'Set-Cookie': 'setCookie', // toggle error by commenting this line
},
};
}
}; Edit: it doesn't work if |
Forgive me for reusing a repo, but here: https://github.com/tcc-sejohnson/svelte-node-build-error That's the minimum I can use to get the error to show up. Maybe it has something to do with |
Looks like this issue has resurfaced according to reports on Discord |
Describe the bug
Check out my implementation of a
get
endpoint:This causes the following linting error:
The problem arises because 'Set-Cookie' is not set to anything on the first segment of the
if
statement. This seems like a pretty reasonable use-case -- I may want to set a cookie or not set a cookie based on application state, but the typing ofServerRequest
doesn't seem to allow for different sets of conditional headers.To Reproduce
Make an endpoint similar to mine. In one branch of an
if
statement, add aSet-Cookie
header. In another, don't add aSet-Cookie
header.Expected behavior
Typing of ServerResponse allows for a non-static set of headers.
Severity
Low.
The text was updated successfully, but these errors were encountered: