{"action":"opened","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10058","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10058/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10058/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10058/events","html_url":"https://github.com/Microsoft/TypeScript/issues/10058","id":168539170,"number":10058,"title":"Export a TypeScript class from another file than it has been defined in","user":{"login":"Loilo","id":1922624,"avatar_url":"https://avatars.githubusercontent.com/u/1922624?v=3","gravatar_id":"","url":"https://api.github.com/users/Loilo","html_url":"https://github.com/Loilo","followers_url":"https://api.github.com/users/Loilo/followers","following_url":"https://api.github.com/users/Loilo/following{/other_user}","gists_url":"https://api.github.com/users/Loilo/gists{/gist_id}","starred_url":"https://api.github.com/users/Loilo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Loilo/subscriptions","organizations_url":"https://api.github.com/users/Loilo/orgs","repos_url":"https://api.github.com/users/Loilo/repos","events_url":"https://api.github.com/users/Loilo/events{/privacy}","received_events_url":"https://api.github.com/users/Loilo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-31T21:26:03Z","updated_at":"2016-07-31T21:26:03Z","closed_at":null,"body":"This is a question I first asked on [StackOverflow](http://stackoverflow.com/questions/38655711/export-a-typescript-class-from-another-file-than-it-has-been-defined-in) but apparently nobody actually knows. I'm posting it here because it looks like a quite common scenario which I think is either already achievable somehow (which then should be in the docs in my opinion) or impossible on purpose for which the design-wise reasons would be interesting.\r\n\r\nI wrote a small library in TypeScript and I've been trying to export its classes in a single place. The goal here is to make the classes available to a browser via a (nested) global object represented by nested TypeScript namespaces. My goal on the other hand is for each class to be agnostic of how they are made available to the outside.\r\n\r\nLet's assume I've got a class `Foo`\r\n\r\n```typescript\r\n// lib/foo.ts\r\nexport class Foo {}\r\n```\r\n\r\nNow I want to make this available to whoever uses the package via the `MyModule` namespace defined in another file. How would I achieve this? I thought of two potential solutions to this, but both do have their downsides which makes them basically useless.\r\n\r\nI could define a variable and assign the class to it:\r\n\r\n```typescript\r\n// api.ts\r\nimport { Foo as MyFoo } from \"./lib/foo\";\r\n\r\nexport namespace MyModule {\r\n    export const Foo = MyFoo;\r\n}\r\n```\r\n\r\nThis will in fact allow me to create instances of the class from an external place like `new MyModule.Foo` but won't give me the possibility to use them as types since then\r\n\r\n```typescript\r\nimport { MyModule } from \"path/to/module/api\";\r\n\r\nlet myFooInstance: MyModule.Foo;\r\n```\r\n\r\nwill throw a TypeScript error stating that\r\n\r\n> Module \"path/to/module/api\" has no exported member 'Foo'\r\n\r\nThe other way around I tried to use `export type Foo = MyFoo` instead of `const` and while this is usable as a type I obviously can't instantiate the class since it's just an alias.\r\n\r\nSo: Is it generally possible to export classes from namespace in a third place, did I overlook a certain practice for this or is this not possible by design?"}}
{"actor":{"display_login":"Loilo"}}