diff --git a/deno_dist/context.ts b/deno_dist/context.ts index 99fe18c98..be844d62e 100644 --- a/deno_dist/context.ts +++ b/deno_dist/context.ts @@ -1,6 +1,6 @@ import type { HonoRequest } from './request.ts' -import type { Env, FetchEventLike, NotFoundHandler, Input, TypedResponse } from './types.ts' -import { resolveCallback, HtmlEscapedCallbackPhase } from './utils/html.ts' +import type { Env, FetchEventLike, Input, NotFoundHandler, TypedResponse } from './types.ts' +import { HtmlEscapedCallbackPhase, resolveCallback } from './utils/html.ts' import type { RedirectStatusCode, StatusCode } from './utils/http-status.ts' import type { JSONValue, JSONParsed, IsAny, Simplify } from './utils/types.ts' @@ -224,7 +224,18 @@ export class Context< */ render: Renderer = (...args) => this.renderer(...args) - setLayout = (layout: Layout) => (this.layout = layout) + setLayout: ( + layout: Layout< + PropsForRenderer & { + Layout: Layout + } + > + ) => Layout< + PropsForRenderer & { + Layout: Layout + } + > = (layout) => (this.layout = layout) + getLayout = () => this.layout /** diff --git a/deno_dist/hono-base.ts b/deno_dist/hono-base.ts index b49a6fc33..ed719bda0 100644 --- a/deno_dist/hono-base.ts +++ b/deno_dist/hono-base.ts @@ -233,7 +233,7 @@ class Hono< * }) * ``` */ - onError = (handler: ErrorHandler) => { + onError: (handler: ErrorHandler) => Hono = (handler) => { this.errorHandler = handler return this } @@ -247,7 +247,7 @@ class Hono< * ``` * @see https://hono.dev/api/hono#not-found */ - notFound = (handler: NotFoundHandler) => { + notFound: (handler: NotFoundHandler) => Hono = (handler) => { this.notFoundHandler = handler return this } @@ -391,12 +391,12 @@ class Hono< * ``` * @see https://hono.dev/api/hono#request */ - request = ( + request: ( input: RequestInfo | URL, requestInit?: RequestInit, Env?: E['Bindings'] | {}, executionCtx?: ExecutionContext - ) => { + ) => Response | Promise = (input, requestInit, Env, executionCtx) => { if (input instanceof Request) { if (requestInit !== undefined) { input = new Request(input, requestInit) diff --git a/deno_dist/request.ts b/deno_dist/request.ts index ea1825379..6fd80d42b 100644 --- a/deno_dist/request.ts +++ b/deno_dist/request.ts @@ -289,7 +289,7 @@ export class HonoRequest

{ * ``` * @see https://hono.dev/api/request#url */ - get url() { + get url(): string { return this.raw.url } @@ -303,7 +303,7 @@ export class HonoRequest

{ * ``` * @see https://hono.dev/api/request#method */ - get method() { + get method(): string { return this.raw.method } diff --git a/deno_dist/router/smart-router/router.ts b/deno_dist/router/smart-router/router.ts index 9c35f2b70..f0ade4671 100644 --- a/deno_dist/router/smart-router/router.ts +++ b/deno_dist/router/smart-router/router.ts @@ -59,7 +59,7 @@ export class SmartRouter implements Router { return res as Result } - get activeRouter() { + get activeRouter(): Router { if (this.routes || this.routers.length !== 1) { throw new Error('No active router has been determined yet.') } diff --git a/deno_dist/utils/buffer.ts b/deno_dist/utils/buffer.ts index 075c3d5ec..5ba55a4e0 100644 --- a/deno_dist/utils/buffer.ts +++ b/deno_dist/utils/buffer.ts @@ -48,7 +48,10 @@ export const bufferToString = (buffer: ArrayBuffer): string => { return buffer } -export const bufferToFormData = (arrayBuffer: ArrayBuffer, contentType: string) => { +export const bufferToFormData = ( + arrayBuffer: ArrayBuffer, + contentType: string +): Promise => { const response = new Response(arrayBuffer, { headers: { 'Content-Type': contentType, diff --git a/src/context.ts b/src/context.ts index 8de2f9e30..7cb776f8a 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1,6 +1,6 @@ import type { HonoRequest } from './request' -import type { Env, FetchEventLike, NotFoundHandler, Input, TypedResponse } from './types' -import { resolveCallback, HtmlEscapedCallbackPhase } from './utils/html' +import type { Env, FetchEventLike, Input, NotFoundHandler, TypedResponse } from './types' +import { HtmlEscapedCallbackPhase, resolveCallback } from './utils/html' import type { RedirectStatusCode, StatusCode } from './utils/http-status' import type { JSONValue, JSONParsed, IsAny, Simplify } from './utils/types' @@ -224,7 +224,18 @@ export class Context< */ render: Renderer = (...args) => this.renderer(...args) - setLayout = (layout: Layout) => (this.layout = layout) + setLayout: ( + layout: Layout< + PropsForRenderer & { + Layout: Layout + } + > + ) => Layout< + PropsForRenderer & { + Layout: Layout + } + > = (layout) => (this.layout = layout) + getLayout = () => this.layout /** diff --git a/src/hono-base.ts b/src/hono-base.ts index cb4092e38..970666cc9 100644 --- a/src/hono-base.ts +++ b/src/hono-base.ts @@ -233,7 +233,7 @@ class Hono< * }) * ``` */ - onError = (handler: ErrorHandler) => { + onError: (handler: ErrorHandler) => Hono = (handler) => { this.errorHandler = handler return this } @@ -247,7 +247,7 @@ class Hono< * ``` * @see https://hono.dev/api/hono#not-found */ - notFound = (handler: NotFoundHandler) => { + notFound: (handler: NotFoundHandler) => Hono = (handler) => { this.notFoundHandler = handler return this } @@ -391,12 +391,12 @@ class Hono< * ``` * @see https://hono.dev/api/hono#request */ - request = ( + request: ( input: RequestInfo | URL, requestInit?: RequestInit, Env?: E['Bindings'] | {}, executionCtx?: ExecutionContext - ) => { + ) => Response | Promise = (input, requestInit, Env, executionCtx) => { if (input instanceof Request) { if (requestInit !== undefined) { input = new Request(input, requestInit) diff --git a/src/request.ts b/src/request.ts index b5fd8546e..7c028aee5 100644 --- a/src/request.ts +++ b/src/request.ts @@ -289,7 +289,7 @@ export class HonoRequest

{ * ``` * @see https://hono.dev/api/request#url */ - get url() { + get url(): string { return this.raw.url } @@ -303,7 +303,7 @@ export class HonoRequest

{ * ``` * @see https://hono.dev/api/request#method */ - get method() { + get method(): string { return this.raw.method } diff --git a/src/router/smart-router/router.ts b/src/router/smart-router/router.ts index 7b0510d87..aa1201122 100644 --- a/src/router/smart-router/router.ts +++ b/src/router/smart-router/router.ts @@ -59,7 +59,7 @@ export class SmartRouter implements Router { return res as Result } - get activeRouter() { + get activeRouter(): Router { if (this.routes || this.routers.length !== 1) { throw new Error('No active router has been determined yet.') } diff --git a/src/utils/buffer.ts b/src/utils/buffer.ts index fecfd82eb..6d24f692f 100644 --- a/src/utils/buffer.ts +++ b/src/utils/buffer.ts @@ -48,7 +48,10 @@ export const bufferToString = (buffer: ArrayBuffer): string => { return buffer } -export const bufferToFormData = (arrayBuffer: ArrayBuffer, contentType: string) => { +export const bufferToFormData = ( + arrayBuffer: ArrayBuffer, + contentType: string +): Promise => { const response = new Response(arrayBuffer, { headers: { 'Content-Type': contentType,