elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
9.74k stars 207 forks source link

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

Closed EvHaus closed 1 month ago

EvHaus commented 1 month ago

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

SaltyAom commented 1 month ago

Hi, Elysia 1.1 has renamed Set-Cookie to set-cookie to force case-sensitivity consistency for HTTP headers and auto-completion See #99 https://github.com/elysiajs/elysia/blob/8173d905944b8b305f8989985abe7760af681de9/src/types.ts#L1393,

EvHaus commented 1 month ago

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

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