You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
declaration: Namespace which exports class can't be merged with variable #13536
// Use interface, because `got` function has `delete` property.interfaceGotApi{(): any;delete(): any;}declarevargot: GotApi;declarenamespacegot{exportclassHTTPErrorextendsError{}}export=got;
Expected behavior:
No errors. HttpError class is available using got exported variable:
import*asgotfrom'got';// let error = ...if(errorinstanceofgot.HTTPError){}
Also, I propose to make error message is more detailed, because current message error TS2300: Duplicate identifier 'got'. is cryptic at first glance. For example, namespace and variable declaration can't be merged.
var got: ()=> any is treated as a variable, and not as a function declaration. the reason is a variable can be assigned to later on where as a function can not.
Mohamed Hegazy (@mhegazy) So why is it then not allowed to merge a declare const with a declare namespace? AFAIK, const is also not assignable more than once.
Activity
aluanhaddad commentedon Jan 17, 2017
Note that the GotApi interface is not exported
ikokostya commentedon Jan 17, 2017
How interface should be exported? This code (similar to request declaration) also isn't compiled with the same error:
If remove class export from namespace, compilation is completed:
mhegazy commentedon Jan 17, 2017
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:
ikokostya commentedon Jan 17, 2017
As I understand from documentation about declaration merging function and variable are value creating declarations, i.e. code
and
fails to compile. But function declaration is compiled:
Why this happen?
Also, I propose to make error message is more detailed, because current message
error TS2300: Duplicate identifier 'got'.is cryptic at first glance. For example,namespace and variable declaration can't be merged.mhegazy commentedon Jan 17, 2017
var got: ()=> anyis treated as a variable, and not as a function declaration. the reason is a variable can be assigned to later on where as a function can not.ikokostya commentedon Jan 17, 2017
Mohamed Hegazy (@mhegazy) Thanks for explanation.
BendingBender commentedon Jul 22, 2017
Mohamed Hegazy (@mhegazy) So why is it then not allowed to merge a
declare constwith adeclare namespace? AFAIK,constis also not assignable more than once.