-
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
declaration: Namespace which exports class can't be merged with variable #13536
Comments
Note that the GotApi interface is not exported |
How interface should be exported? This code (similar to request declaration) also isn't compiled with the same error: declare namespace got {
export interface GotApi {
(): any;
delete(): any;
}
export class HTTPError {}
}
declare var got: got.GotApi;
export = got; If remove class export from namespace, compilation is completed: interface GotApi {
(): any;
delete(): any;
}
declare var got: GotApi;
declare namespace got {
// export class HTTPError extends Error {} <--- Comment this line
}
export = got; |
Ideally this would be rewitten as function+namespace but it can not, #1784 (and #9846) track that. Instantiated namespaces (i.e. ones that has a value in them) can not merge with variables, since one of them will override the other at run-time. you can write your declaration as such: declare class HTTPError { }
interface GotApi {
(): any;
delete(): any;
HTTPError: typeof HTTPError;
}
declare var got: GotApi;
export = got; |
As I understand from documentation about declaration merging function and variable are value creating declarations, i.e. code interface GotApi {
(): any;
}
declare var got: GotApi;
declare namespace got {
export class HTTPError {}
}
export = got; and declare var got: () => any;
declare namespace got {
export class HTTPError {}
}
export = got; fails to compile. But function declaration is compiled: declare function got(): any;
declare namespace got {
export class HTTPError {}
}
export = got; Why this happen? Also, I propose to make error message is more detailed, because current message |
|
@mhegazy Thanks for explanation. |
@mhegazy So why is it then not allowed to merge a |
TypeScript Version: 2.2.0-dev.20170117
I try to write declaration for got module.
Code
Expected behavior:
No errors.
HttpError
class is available usinggot
exported variable:Actual behavior:
I get compiler errors for declaration file:
Used tsconfig.json:
Related issue: #1784
The text was updated successfully, but these errors were encountered: