Issue
I'm trying to create a d.ts file for codebooks.io, which defines delete
as a top level exported function.
https://codehooks.io/docs/appeventapi#appdeleteroute-callback
here is my codebooks-js.d.ts
file so far
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
// here's the problem
export function delete(route: string, callback: Callback): void
}
typescript error given
Identifier expected. 'delete' is a reserved word that cannot be used here.ts(1359)
I expected to be able to use @ts-expect-error
but that doesn't seem to do anything in d.ts file.
how can I work around this?
Solution
You can rename exports in an export
statement like export { internalName as externalName }
, and luckily delete
is not considered a reserved identifier in such a rename. So you can write this:
function _delete(route: string, callback: Callback): void;
export { _delete as delete } // no error
Answered By - jcalz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.