elysiajs / elysia

Ergonomic Framework for Humans

Home Page:https://elysiajs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

v1.1.0 has a regression in the type for set.headers (no longer supports arrays)

EvHaus opened this issue · comments

What version of Elysia.JS is running?

1.1.3

What platform is your computer?

Linux 5.15.153.1-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

new Elysia({ prefix: '/auth' })
  .post('/login', async ({ set }) => {
    const cookie1 = 'first=hello; Domain=.localhost; HttpOnly; Max-Age=2592000; Path=/; SameSite=Lax'
    const cookie2 = 'second=howdy; Domain=.localhost; HttpOnly; Max-Age=2147483647; Path=/; SameSite=Lax'

    // @ts-expect-error This used to work in elysia 1.0.x. It still works in 1.1.0 but TypeScript errors here
    set.headers['Set-Cookie'] = [cookie1, cookie2];

    return true;
  })

What is the expected behavior?

No error, and 2 separate Set-Cookie headers are set on the response.

What do you see instead?

2 separate headers are set correctly, but TypeScript errors with:

api/auth/index.ts:143:4 - error TS2322: Type 'string[]' is not assignable to type 'string'.

143    set.headers['Set-Cookie'] = [cookie1, cookie2];

Additional information

No response

Hi, Elysia 1.1 has renamed Set-Cookie to set-cookie to force case-sensitivity consistency for HTTP headers and auto-completion
See #99

'set-cookie'?: string | string[]
,

Confirmed. Changing Set-Cookie to set-cookie fixed the issue.

I opened a PR to update the docs around this here.