mirror of
https://github.com/honojs/hono.git
synced 2024-12-01 11:51:01 +01:00
fix(types): corrected argument types for Context
methods (#1357)
This commit is contained in:
parent
2b274662e9
commit
88e7650ee8
@ -207,7 +207,7 @@ export class Context<
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return Response immediately if arg is RequestInit.
|
// Return Response immediately if arg is ResponseInit.
|
||||||
if (arg && typeof arg !== 'number') {
|
if (arg && typeof arg !== 'number') {
|
||||||
const res = new Response(data, arg)
|
const res = new Response(data, arg)
|
||||||
const contentType = this._pH?.['content-type']
|
const contentType = this._pH?.['content-type']
|
||||||
@ -254,7 +254,7 @@ export class Context<
|
|||||||
|
|
||||||
body: BodyRespond = (
|
body: BodyRespond = (
|
||||||
data: Data | null,
|
data: Data | null,
|
||||||
arg?: StatusCode | RequestInit,
|
arg?: StatusCode | ResponseInit,
|
||||||
headers?: HeaderRecord
|
headers?: HeaderRecord
|
||||||
): Response => {
|
): Response => {
|
||||||
return typeof arg === 'number'
|
return typeof arg === 'number'
|
||||||
@ -264,7 +264,7 @@ export class Context<
|
|||||||
|
|
||||||
text: TextRespond = (
|
text: TextRespond = (
|
||||||
text: string,
|
text: string,
|
||||||
arg?: StatusCode | RequestInit,
|
arg?: StatusCode | ResponseInit,
|
||||||
headers?: HeaderRecord
|
headers?: HeaderRecord
|
||||||
): Response => {
|
): Response => {
|
||||||
// If the header is empty, return Response immediately.
|
// If the header is empty, return Response immediately.
|
||||||
@ -287,7 +287,7 @@ export class Context<
|
|||||||
|
|
||||||
json: JSONRespond = <T = {}>(
|
json: JSONRespond = <T = {}>(
|
||||||
object: T,
|
object: T,
|
||||||
arg?: StatusCode | RequestInit,
|
arg?: StatusCode | ResponseInit,
|
||||||
headers?: HeaderRecord
|
headers?: HeaderRecord
|
||||||
) => {
|
) => {
|
||||||
const body = JSON.stringify(object)
|
const body = JSON.stringify(object)
|
||||||
@ -300,7 +300,7 @@ export class Context<
|
|||||||
|
|
||||||
jsonT: JSONTRespond = <T>(
|
jsonT: JSONTRespond = <T>(
|
||||||
object: InterfaceToType<T> extends JSONValue ? T : JSONValue,
|
object: InterfaceToType<T> extends JSONValue ? T : JSONValue,
|
||||||
arg?: StatusCode | RequestInit,
|
arg?: StatusCode | ResponseInit,
|
||||||
headers?: HeaderRecord
|
headers?: HeaderRecord
|
||||||
): TypedResponse<
|
): TypedResponse<
|
||||||
InterfaceToType<T> extends JSONValue
|
InterfaceToType<T> extends JSONValue
|
||||||
@ -319,7 +319,7 @@ export class Context<
|
|||||||
|
|
||||||
html: HTMLRespond = (
|
html: HTMLRespond = (
|
||||||
html: string,
|
html: string,
|
||||||
arg?: StatusCode | RequestInit,
|
arg?: StatusCode | ResponseInit,
|
||||||
headers?: HeaderRecord
|
headers?: HeaderRecord
|
||||||
): Response => {
|
): Response => {
|
||||||
this._pH ??= {}
|
this._pH ??= {}
|
||||||
|
@ -207,7 +207,7 @@ export class Context<
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return Response immediately if arg is RequestInit.
|
// Return Response immediately if arg is ResponseInit.
|
||||||
if (arg && typeof arg !== 'number') {
|
if (arg && typeof arg !== 'number') {
|
||||||
const res = new Response(data, arg)
|
const res = new Response(data, arg)
|
||||||
const contentType = this._pH?.['content-type']
|
const contentType = this._pH?.['content-type']
|
||||||
@ -254,7 +254,7 @@ export class Context<
|
|||||||
|
|
||||||
body: BodyRespond = (
|
body: BodyRespond = (
|
||||||
data: Data | null,
|
data: Data | null,
|
||||||
arg?: StatusCode | RequestInit,
|
arg?: StatusCode | ResponseInit,
|
||||||
headers?: HeaderRecord
|
headers?: HeaderRecord
|
||||||
): Response => {
|
): Response => {
|
||||||
return typeof arg === 'number'
|
return typeof arg === 'number'
|
||||||
@ -264,7 +264,7 @@ export class Context<
|
|||||||
|
|
||||||
text: TextRespond = (
|
text: TextRespond = (
|
||||||
text: string,
|
text: string,
|
||||||
arg?: StatusCode | RequestInit,
|
arg?: StatusCode | ResponseInit,
|
||||||
headers?: HeaderRecord
|
headers?: HeaderRecord
|
||||||
): Response => {
|
): Response => {
|
||||||
// If the header is empty, return Response immediately.
|
// If the header is empty, return Response immediately.
|
||||||
@ -287,7 +287,7 @@ export class Context<
|
|||||||
|
|
||||||
json: JSONRespond = <T = {}>(
|
json: JSONRespond = <T = {}>(
|
||||||
object: T,
|
object: T,
|
||||||
arg?: StatusCode | RequestInit,
|
arg?: StatusCode | ResponseInit,
|
||||||
headers?: HeaderRecord
|
headers?: HeaderRecord
|
||||||
) => {
|
) => {
|
||||||
const body = JSON.stringify(object)
|
const body = JSON.stringify(object)
|
||||||
@ -300,7 +300,7 @@ export class Context<
|
|||||||
|
|
||||||
jsonT: JSONTRespond = <T>(
|
jsonT: JSONTRespond = <T>(
|
||||||
object: InterfaceToType<T> extends JSONValue ? T : JSONValue,
|
object: InterfaceToType<T> extends JSONValue ? T : JSONValue,
|
||||||
arg?: StatusCode | RequestInit,
|
arg?: StatusCode | ResponseInit,
|
||||||
headers?: HeaderRecord
|
headers?: HeaderRecord
|
||||||
): TypedResponse<
|
): TypedResponse<
|
||||||
InterfaceToType<T> extends JSONValue
|
InterfaceToType<T> extends JSONValue
|
||||||
@ -319,7 +319,7 @@ export class Context<
|
|||||||
|
|
||||||
html: HTMLRespond = (
|
html: HTMLRespond = (
|
||||||
html: string,
|
html: string,
|
||||||
arg?: StatusCode | RequestInit,
|
arg?: StatusCode | ResponseInit,
|
||||||
headers?: HeaderRecord
|
headers?: HeaderRecord
|
||||||
): Response => {
|
): Response => {
|
||||||
this._pH ??= {}
|
this._pH ??= {}
|
||||||
|
Loading…
Reference in New Issue
Block a user