Skip to content
Myr

fix(types): use correct return type for c.html depending on input (#2973)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Andreas Storesund Madsen · committed by GitHub · parent 614dff0 · Browse files · 2 files+12 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+12 added−7 removed

  • tests:+4 added−3 removed
  • other:+8 added−4 removed

2 files+12 added−7 removed

modified:src/context.test.ts+4 added-3 removed
34 unmodified lines
35 expect(res.headers.get('X-Custom')).toBe('Message')36 })3738 it('c.html()', async () => {39 const res = await c.html('<h1>Hello! Hono!</h1>', 201, { 'X-Custom': 'Message' })39 const res: Response = c.html('<h1>Hello! Hono!</h1>', 201, { 'X-Custom': 'Message' })40 expect(res.status).toBe(201)41 expect(res.headers.get('Content-Type')).toMatch('text/html')42 expect(await res.text()).toBe('<h1>Hello! Hono!</h1>')43 expect(res.headers.get('X-Custom')).toBe('Message')44 })4546 it('c.html() with async', async () => {47 const res = await c.html(48 new Promise((resolve) => setTimeout(() => resolve('<h1>Hello! Hono!</h1>'), 0)),47 const resPromise: Promise<Response> = c.html(48 new Promise<string>((resolve) => setTimeout(() => resolve('<h1>Hello! Hono!</h1>'), 0)),49 201,50 {51 'X-Custom': 'Message',52 }53 )54 const res = await resPromise55 expect(res.status).toBe(201)56 expect(res.headers.get('Content-Type')).toMatch('text/html')57 expect(await res.text()).toBe('<h1>Hello! Hono!</h1>')58 expect(res.headers.get('X-Custom')).toBe('Message')
401 unmodified lines
modified:src/context.ts+8 added-4 removed
173 unmodified lines
174 *175 * @returns A Response object or a Promise that resolves to a Response object.176 */177interface HTMLRespond {178 (html: string | Promise<string>, status?: StatusCode, headers?: HeaderRecord):179 | Response180 | Promise<Response>181 (html: string | Promise<string>, init?: ResponseInit): Response | Promise<Response>178 <T extends string | Promise<string>>(179 html: T,180 status?: StatusCode,181 headers?: HeaderRecord182 ): T extends string ? Response : Promise<Response>183 <T extends string | Promise<string>>(html: T, init?: ResponseInit): T extends string184 ? Response185 : Promise<Response>186}187188/**189 * Options for configuring the context.
566 unmodified lines