I am currently in the process of generating a d.ts file for codebooks.io, where I need to define the function delete
as an exported top-level function.
This is what my codebooks-js.d.ts
file looks like at the moment:
declare module "codehooks-js" {
export type Method = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH'
export type RequestObject = {
headers: Object,
query: Object,
params: Object,
body: any,
path: string,
apipath: string,
originalUrl: string,
method: Method,
hostname: string,
}
export type ResponseObject = {
set: (header: string, value: string) => void,
headers: (object: Object) => void,
status: (httpStatusCode: number) => void,
json: (object: Object) => void,
write: (data: string | unknown) => void,
send: (data: string) => void,
end: () => void,
}
export type Next = () => void
export type Callback = (request: RequestObject, response: ResponseObject, next: Next) => void
export function init(): void
export function use(callback: Callback): void
export function get(route: string): void
export function get(route: string, callback: Callback): void
export function post(route: string, callback: Callback): void
export function put(route: string, callback: Callback): void
export function patch(route: string, callback: Callback): void
// encountering a problem here
export function delete(route: string, callback: Callback): void
}
An error from TypeScript has occurred:
Identifier expected. 'delete' is a reserved word that cannot be used here.ts(1359)
I tried using @ts-expect-error
, but it does not seem to have any effect in a d.ts file. What should I do to resolve this issue?