Perhaps you'd prefer not to receive the advice of "don't do that," but it might be the most sound recommendation. Utilizing reserved words as identifiers doesn't always lead to failure, however, encountering issues in certain JavaScript environments is a possibility. Nevertheless, let's proceed anyway.
This situation presents an interesting conundrum. I would like to employ a quoted string literal similarly to how one would use with a method or property name, as stated in the TypeScript specification:
String literals may be used to give properties names that are not valid identifiers
But unfortunately, this approach does not apply to naming functions, which must adhere to valid identifier rules.
An alternative option appears to involve assigning the function a valid name and then exporting an alias for it:
declare namespace Http {
export type HttpOptions = ...
export type HttpPromise<T> = ...
export function get<T>(url: string, options?: HttpOptions): HttpPromise<T>;
function del<T>(url: string, options?: HttpOptions): HttpPromise<T>;
export { del as delete }; // no error
}
The process seems feasible, although documentation supporting this method is currently scarce. Initially, one might assume that using a reserved word within the as
clause would fail (quoting it also generates an error), but surprisingly, it functions correctly:
Http.get('url') // okay
Http.delete('url') // apparently okay but you probably shouldn't
Http['delete']('url') // okay
Does this clarification assist you?
Another suggestion involves employing declaration merging, though its functionality also raises some eyebrows according to instances of surprise. In this scenario, start by declaring the namespace solely with type aliases, followed by merging a declared constant bearing the same name containing the properties. It may seem fragile and unconventional, but it has proven effective in my case:
declare namespace Http {
export type HttpOptions = ...
export type HttpPromise<T> = ...
}
declare const Http: {
get<T>(url: string, options?: Http.HttpOptions): Http.HttpPromise<T>;
"delete"<T>(url: string, options?: Http.HttpOptions): Http.HttpPromise<T>;
}
I hope one of these approaches proves beneficial to you; I wish you the best of luck!