{"action":"closed","issue":{"url":"https://api.github.com/repos/palantir/tslint/issues/261","repository_url":"https://api.github.com/repos/palantir/tslint","labels_url":"https://api.github.com/repos/palantir/tslint/issues/261/labels{/name}","comments_url":"https://api.github.com/repos/palantir/tslint/issues/261/comments","events_url":"https://api.github.com/repos/palantir/tslint/issues/261/events","html_url":"https://github.com/palantir/tslint/issues/261","id":54814633,"number":261,"title":"add rule: new() in an interface must not return the same interface.","user":{"login":"JeroMiya","id":320332,"avatar_url":"https://avatars2.githubusercontent.com/u/320332?v=3","gravatar_id":"","url":"https://api.github.com/users/JeroMiya","html_url":"https://github.com/JeroMiya","followers_url":"https://api.github.com/users/JeroMiya/followers","following_url":"https://api.github.com/users/JeroMiya/following{/other_user}","gists_url":"https://api.github.com/users/JeroMiya/gists{/gist_id}","starred_url":"https://api.github.com/users/JeroMiya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JeroMiya/subscriptions","organizations_url":"https://api.github.com/users/JeroMiya/orgs","repos_url":"https://api.github.com/users/JeroMiya/repos","events_url":"https://api.github.com/users/JeroMiya/events{/privacy}","received_events_url":"https://api.github.com/users/JeroMiya/received_events","type":"User","site_admin":false},"labels":[{"id":236417479,"url":"https://api.github.com/repos/palantir/tslint/labels/Resolution:%20Fixed","name":"Resolution: Fixed","color":"000000","default":false},{"id":182886787,"url":"https://api.github.com/repos/palantir/tslint/labels/Type:%20Rule%20Suggestion","name":"Type: Rule Suggestion","color":"fbca04","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2015-01-19T21:29:03Z","updated_at":"2017-03-30T15:30:55Z","closed_at":"2017-03-30T15:30:55Z","body":"One common pattern I see in TypeScript type declarations is the inclusion of a new(args...): IInterface in an interface to type a constructor and the thing it constructs in the same interface:\n\n``` typescript\ninterface IConstructable {\n  new(): IConstructable;\n  field: string;\n}\ndeclare var Constructable: IConstructable;\nvar x = new Constructable();\nvar y = new x(); // oops! I didn't intend this to be possible!\n```\n\nAs you can see, this leads to a recursive type. Probably not what you wanted. This rule would enforce that new() in an interface must not return that interface. The right pattern to follow is to separate out the new() into another interface:\n\n``` typescript\ninterface IStringValueBox {\n  value: string;\n}\n\ninterface IStringValueBoxConstructor {\n  new(): IStringValueBox;\n}\n\ndeclare var StringValueBox: IStringValueBoxConstructor;\nvar x = new StringValueBox();\nvar y = new x(); // Error, IStringValueBox does not have a constructor, etc...\n```\n"}}
{"actor":{"display_login":"adidahiya"}}