{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9359","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9359/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9359/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9359/events","html_url":"https://github.com/Microsoft/TypeScript/issues/9359","id":162288298,"number":9359,"title":"Suggestion: preserve both static and instance sides of class types when class is used in value position","user":{"login":"jwbay","id":1320447,"avatar_url":"https://avatars.githubusercontent.com/u/1320447?v=3","gravatar_id":"","url":"https://api.github.com/users/jwbay","html_url":"https://github.com/jwbay","followers_url":"https://api.github.com/users/jwbay/followers","following_url":"https://api.github.com/users/jwbay/following{/other_user}","gists_url":"https://api.github.com/users/jwbay/gists{/gist_id}","starred_url":"https://api.github.com/users/jwbay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwbay/subscriptions","organizations_url":"https://api.github.com/users/jwbay/orgs","repos_url":"https://api.github.com/users/jwbay/repos","events_url":"https://api.github.com/users/jwbay/events{/privacy}","received_events_url":"https://api.github.com/users/jwbay/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-06-25T16:19:49Z","updated_at":"2016-06-26T04:03:56Z","closed_at":null,"body":"Following up on #9358 and #6543. It hasn't stopped bothering me that generic identity functions don't exactly return their incoming types when it comes to classes.\r\n\r\n```ts\r\ndeclare function decorate<T>(Class: T): T;\r\n\r\nclass Foo {\r\n\tstatic bar = 42;\r\n\tbaz () {}\r\n}\r\n\r\n//full type information seems present...\r\nconst DecoratedFoo = decorate(Foo);\r\nDecoratedFoo.bar === 42; //ok\r\nnew DecoratedFoo().baz(); //ok\r\n\r\n//but the instance side has been dropped from the DecoratedFoo type\r\nlet fooConstructor: typeof Foo; //ok\r\nlet foo: Foo; //ok\r\nlet decoratedFooConstructor: typeof DecoratedFoo; //ok\r\nlet decoratedFoo: DecoratedFoo; //error: cannot find name 'DecoratedFoo'\r\n```\r\n\r\nWould it be possible for `decorate(Foo)`'s return type to be `class Foo`, or something equivalent, instead of `typeof Foo`? It's an identity function; I'm trying to tell TypeScript that whatever I'm doing to the class, if anything, is invisible to the caller. The workaround in #6543 is a bit unfortunate in that it places the burden of the aliasing/merging on each and every caller instead of in the function that's doing the work.\r\n\r\n**Edit**: Simpler repro, looks like it has nothing to do with identity functions and everything to do with a class  being assigned to a value, whether via local alias or passed as argument. Would just like a class to stay a class everywhere it goes :)\r\n\r\n```ts\r\nclass Foo { }\r\nconst Bar = Foo;\r\nlet bar: Bar; //error: cannot find name 'Bar'\r\n```"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/228583176","html_url":"https://github.com/Microsoft/TypeScript/issues/9359#issuecomment-228583176","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9359","id":228583176,"user":{"login":"aleksey-bykov","id":937933,"avatar_url":"https://avatars.githubusercontent.com/u/937933?v=3","gravatar_id":"","url":"https://api.github.com/users/aleksey-bykov","html_url":"https://github.com/aleksey-bykov","followers_url":"https://api.github.com/users/aleksey-bykov/followers","following_url":"https://api.github.com/users/aleksey-bykov/following{/other_user}","gists_url":"https://api.github.com/users/aleksey-bykov/gists{/gist_id}","starred_url":"https://api.github.com/users/aleksey-bykov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aleksey-bykov/subscriptions","organizations_url":"https://api.github.com/users/aleksey-bykov/orgs","repos_url":"https://api.github.com/users/aleksey-bykov/repos","events_url":"https://api.github.com/users/aleksey-bykov/events{/privacy}","received_events_url":"https://api.github.com/users/aleksey-bykov/received_events","type":"User","site_admin":false},"created_at":"2016-06-26T04:03:56Z","updated_at":"2016-06-26T04:03:56Z","body":"by the definition of the identity function the result is always of the type of its argument, if so then you don't need to call it to get the type, because you got the type already before you called it\r\n\r\nproblem is that it is not and identity function, it's a transformation from T to another U, but then why is it called identity?"}}
{"actor":{"display_login":"aleksey-bykov"}}