-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exporting a keyword-named function in a module #1784
Comments
👍 |
This isn't allowed at the moment because JavaScript doesn't allow that pattern either. Presumably Q has actually defined it as something like In the meantime one workaround would be to use a merged class and module. declare class Q {
static try();
}
declare module Q { }
Q.try(); The downside here is that now the type system will think Q has a construct signature and a prototype property. |
I also encountered this or a variation thereof. I was trying to do a literal port of the following JavaScript, exports.delete = function(args) { ... } but, could not use the following TypeScript export function delete(args) { ... } In the end I found the JavaScript version still works in the TypeScript file and had to stick with that for this function. |
Related is #9846. If I recall, we decided that it was too complex because you can rewrite your module as follows: // Exported values go here.
interface X {
delete(args: any[]): void;
}
// Exported types go here.
declare namespace x {
interface Foo {
// ...
}
}
declare var x: X;
export = x; |
function del(...args) { }
export { del as delete } turns out this errors on import, sigh... |
The type definition file for the Q module has the following problem:
The compiler doesn't accept the type definition because it thinks a try/catch block is about to begin.
Is there any way to define this exported function?
The text was updated successfully, but these errors were encountered: