From bc882d42dd6af523f492274098d1c7c446cd675a Mon Sep 17 00:00:00 2001 From: saltyaom Date: Wed, 14 Jan 2026 11:33:45 +0700 Subject: [PATCH] :blue_book: doc: document changelog --- CHANGELOG.md | 2 ++ src/adapter/bun/handler.ts | 52 ++++++++++++--------------- src/adapter/web-standard/handler.ts | 56 ++++++++++++++--------------- 3 files changed, 52 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 361da414..48c66c84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,13 @@ # 1.4.22 Improvement: - use imperative check for `replaceURLPath` instead of allocating `new URL` +- reduce ts-ignore/ts-expect-error on promise map handler Bug fix: - [#1671](https://github.com/elysiajs/elysia/issues/1671) mount produces incorrect URL path when Elysia instance has prefix option - [https://github.com/elysiajs/elysia/issues/1617](https://github.com/elysiajs/elysia/issues/1617), [#1623](https://github.com/elysiajs/elysia/pull/1623) AOT compilation removes beforeHandle when using arrow function expression - [#1667](https://github.com/elysiajs/elysia/issues/1667) skip body parsing on mount with dynamic mode +- [#1662](https://github.com/elysiajs/elysia/pull/1662) custom thenable fallback in `mapCompactResponse` causing runtime crash with undefined variable - [#1661](https://github.com/elysiajs/elysia/pull/1661), [#1663](https://github.com/elysiajs/elysia/pull/1663) fix SSE double-wrapping bug when returning pre-formatted Response - ValueError with summary missing types - Elysia not using Bun.routes by default diff --git a/src/adapter/bun/handler.ts b/src/adapter/bun/handler.ts index 626caa4d..c9b61783 100644 --- a/src/adapter/bun/handler.ts +++ b/src/adapter/bun/handler.ts @@ -37,10 +37,7 @@ export const mapResponse = ( return new Response(JSON.stringify(response), set as any) case 'ElysiaFile': - return handleFile( - (response as ElysiaFile).value as File, - set - ) + return handleFile((response as ElysiaFile).value as File, set) case 'File': return handleFile(response as File, set) @@ -122,10 +119,8 @@ export const mapResponse = ( ) return handleStream(response as any, set, request) as any - // @ts-expect-error - if (typeof response?.then === 'function') - // @ts-expect-error - return response.then((x) => mapResponse(x, set)) as any + if (typeof (response as Promise)?.then === 'function') + return (response as Promise).then((x) => mapResponse(x, set)) as any // @ts-expect-error if (typeof response?.toResponse === 'function') @@ -206,10 +201,9 @@ export const mapEarlyResponse = ( return handleResponse(response as Response, set, request) case 'Promise': - // @ts-ignore return (response as Promise).then((x) => mapEarlyResponse(x, set) - ) + ) as any case 'Error': return errorToResponse(response as Error, set) @@ -262,10 +256,10 @@ export const mapEarlyResponse = ( ) return handleStream(response as any, set, request) as any - // @ts-expect-error - if (typeof response?.then === 'function') - // @ts-expect-error - return response.then((x) => mapEarlyResponse(x, set)) as any + if (typeof (response as Promise)?.then === 'function') + return (response as Promise).then((x) => + mapEarlyResponse(x, set) + ) as any // @ts-expect-error if (typeof response?.toResponse === 'function') @@ -328,11 +322,10 @@ export const mapEarlyResponse = ( return response as Response case 'Promise': - // @ts-ignore return (response as Promise).then((x) => { const r = mapEarlyResponse(x, set) if (r !== undefined) return r - }) + }) as any case 'Error': return errorToResponse(response as Error, set) @@ -381,10 +374,10 @@ export const mapEarlyResponse = ( ) return handleStream(response as any, set, request) as any - // @ts-expect-error - if (typeof response?.then === 'function') - // @ts-expect-error - return response.then((x) => mapEarlyResponse(x, set)) as any + if (typeof (response as Promise)?.then === 'function') + return (response as Promise).then((x) => + mapEarlyResponse(x, set) + ) as any // @ts-expect-error if (typeof response?.toResponse === 'function') @@ -458,7 +451,7 @@ export const mapCompactResponse = ( return errorToResponse(response as Error) case 'Promise': - return (response as any as Promise).then((x) => + return (response as Promise).then((x) => mapCompactResponse(x, request) ) as any @@ -501,12 +494,12 @@ export const mapCompactResponse = ( ) return handleStream(response as any, undefined, request) as any - // @ts-expect-error - if (typeof response?.then === 'function') - // @ts-expect-error - return response.then((x) => mapCompactResponse(x, request)) as any + if (typeof (response as Promise)?.then === 'function') + return (response as Promise).then((x) => + mapCompactResponse(x, request) + ) as any - // @ts-expect-error + // @ts-expect-errors if (typeof response?.toResponse === 'function') return mapCompactResponse((response as any).toResponse()) @@ -532,15 +525,14 @@ export const errorToResponse = (error: Error, set?: Context['set']) => { // @ts-expect-error const raw = error.toResponse() const targetSet = - set ?? ({ headers: {}, status: 200, redirect: '' } as Context['set']) + set ?? + ({ headers: {}, status: 200, redirect: '' } as Context['set']) const apply = (resolved: unknown) => { if (resolved instanceof Response) targetSet.status = resolved.status return mapResponse(resolved, targetSet) } - return typeof raw?.then === 'function' - ? raw.then(apply) - : apply(raw) + return typeof raw?.then === 'function' ? raw.then(apply) : apply(raw) } return new Response( diff --git a/src/adapter/web-standard/handler.ts b/src/adapter/web-standard/handler.ts index aaf29107..ddc9f47a 100644 --- a/src/adapter/web-standard/handler.ts +++ b/src/adapter/web-standard/handler.ts @@ -13,7 +13,7 @@ import { Cookie } from '../../cookies' import { ElysiaCustomStatusResponse } from '../../error' import type { Context } from '../../context' -import type { AnyLocalHook } from '../../types' +import type { AnyLocalHook, MaybePromise } from '../../types' const handleElysiaFile = ( file: ElysiaFile, @@ -149,10 +149,10 @@ export const mapResponse = ( ) return handleStream(response as any, set, request) as any - // @ts-expect-error - if (typeof response?.then === 'function') - // @ts-expect-error - return response.then((x) => mapResponse(x, set)) as any + if (typeof (response as Promise)?.then === 'function') + return (response as Promise).then((x) => + mapResponse(x, set) + ) as any // @ts-expect-error if (typeof response?.toResponse === 'function') @@ -234,10 +234,9 @@ export const mapEarlyResponse = ( return handleResponse(response as Response, set, request) case 'Promise': - // @ts-ignore return (response as Promise).then((x) => mapEarlyResponse(x, set) - ) + ) as any case 'Error': return errorToResponse(response as Error, set) @@ -290,10 +289,10 @@ export const mapEarlyResponse = ( ) return handleStream(response as any, set, request) as any - // @ts-expect-error - if (typeof response?.then === 'function') - // @ts-expect-error - return response.then((x) => mapEarlyResponse(x, set)) as any + if (typeof (response as Promise)?.then === 'function') + return (response as Promise).then((x) => + mapEarlyResponse(x, set) + ) as any // @ts-expect-error if (typeof response?.toResponse === 'function') @@ -357,11 +356,10 @@ export const mapEarlyResponse = ( return response as Response case 'Promise': - // @ts-ignore return (response as Promise).then((x) => { const r = mapEarlyResponse(x, set) if (r !== undefined) return r - }) + }) as any case 'Error': return errorToResponse(response as Error, set) @@ -410,10 +408,10 @@ export const mapEarlyResponse = ( ) return handleStream(response as any, set, request) as any - // @ts-expect-error - if (typeof response?.then === 'function') - // @ts-expect-error - return response.then((x) => mapEarlyResponse(x, set)) as any + if (typeof (response as Promise)?.then === 'function') + return (response as Promise).then((x) => + mapEarlyResponse(x, set) + ) as any // @ts-expect-error if (typeof response?.toResponse === 'function') @@ -534,10 +532,10 @@ export const mapCompactResponse = ( ) return handleStream(response as any, undefined, request) as any - // @ts-expect-error - if (typeof response?.then === 'function') - // @ts-expect-error - return response.then((x) => mapCompactResponse(x, request)) as any + if (typeof (response as Promise)?.then === 'function') + return (response as Promise).then((x) => + mapCompactResponse(x, request) + ) as any // @ts-expect-error if (typeof response?.toResponse === 'function') @@ -559,21 +557,23 @@ export const mapCompactResponse = ( } } -export const errorToResponse = (error: Error, set?: Context['set']) => { - // @ts-expect-error +export const errorToResponse = ( + error: Error & { toResponse?(): MaybePromise }, + set?: Context['set'] +) => { if (typeof error?.toResponse === 'function') { - // @ts-expect-error const raw = error.toResponse() const targetSet = - set ?? ({ headers: {}, status: 200, redirect: '' } as Context['set']) + set ?? + ({ headers: {}, status: 200, redirect: '' } as Context['set']) + const apply = (resolved: unknown) => { if (resolved instanceof Response) targetSet.status = resolved.status return mapResponse(resolved, targetSet) } - return typeof raw?.then === 'function' - ? raw.then(apply) - : apply(raw) + // @ts-ignore + return typeof raw?.then === 'function' ? raw.then(apply) : apply(raw) } return new Response(