{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/21987","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/21987/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/21987/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/21987/events","html_url":"https://github.com/Microsoft/TypeScript/issues/21987","id":297697238,"number":21987,"title":"Index Signature doesn't work when instantiating an object using a class","user":{"login":"ratoaq2","id":9292886,"avatar_url":"https://avatars3.githubusercontent.com/u/9292886?v=4","gravatar_id":"","url":"https://api.github.com/users/ratoaq2","html_url":"https://github.com/ratoaq2","followers_url":"https://api.github.com/users/ratoaq2/followers","following_url":"https://api.github.com/users/ratoaq2/following{/other_user}","gists_url":"https://api.github.com/users/ratoaq2/gists{/gist_id}","starred_url":"https://api.github.com/users/ratoaq2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ratoaq2/subscriptions","organizations_url":"https://api.github.com/users/ratoaq2/orgs","repos_url":"https://api.github.com/users/ratoaq2/repos","events_url":"https://api.github.com/users/ratoaq2/events{/privacy}","received_events_url":"https://api.github.com/users/ratoaq2/received_events","type":"User","site_admin":false},"labels":[{"id":371615203,"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Working%20as%20Intended","name":"Working as Intended","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-02-16T07:03:02Z","updated_at":"2018-02-17T18:43:26Z","closed_at":null,"author_association":"NONE","body":"Typescript Version: 2.6.2\r\n\r\n```\r\ninterface MyInterface {\r\n  [key: string]: () => string;\r\n}\r\n\r\nconst thisWorksObject: MyInterface = {\r\n  someMethod() {\r\n    return 'a';\r\n  }\r\n};\r\n\r\nclass MyClass {\r\n  someMethod() {\r\n    return 'a';\r\n  }\r\n}\r\n\r\nconst thisDoesntWorkObject: MyInterface = new MyClass();\r\n```\r\n\r\nThe last line shows the following error:\r\n```\r\n[ts]\r\nType 'MyClass' is not assignable to type 'MyInterface'.\r\n  Index signature is missing in type 'MyClass'.\r\nconst thisDoesntWorkObject: MyInterface\r\n```\r\n\r\nI would like to know if that's expected. Am I missing something?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/366462395","html_url":"https://github.com/Microsoft/TypeScript/issues/21987#issuecomment-366462395","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/21987","id":366462395,"user":{"login":"qwabra","id":5960180,"avatar_url":"https://avatars0.githubusercontent.com/u/5960180?v=4","gravatar_id":"","url":"https://api.github.com/users/qwabra","html_url":"https://github.com/qwabra","followers_url":"https://api.github.com/users/qwabra/followers","following_url":"https://api.github.com/users/qwabra/following{/other_user}","gists_url":"https://api.github.com/users/qwabra/gists{/gist_id}","starred_url":"https://api.github.com/users/qwabra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qwabra/subscriptions","organizations_url":"https://api.github.com/users/qwabra/orgs","repos_url":"https://api.github.com/users/qwabra/repos","events_url":"https://api.github.com/users/qwabra/events{/privacy}","received_events_url":"https://api.github.com/users/qwabra/received_events","type":"User","site_admin":false},"created_at":"2018-02-17T18:43:26Z","updated_at":"2018-02-17T18:43:26Z","author_association":"NONE","body":"@mhegazy, __type check__ didn't work with clases\r\n```ts\r\nclass Resp {\r\n\terror = null\r\n\tdata = null\r\n}\r\ninterface router {\r\n\t[k: string]: (...args: any[]) => Promise<Resp>\r\n}\r\n```\r\ntest with bad function qqw():string\r\nhaven't type check\r\n```ts\r\nclass User implements router {      // < --Index signature is missing in type \r\n\tasync getAll() {\r\n\t\treturn new Resp\r\n\t}\r\n\t//  async getByID() {}\r\n\t//  async getByName() {}\r\n\t//  ... and many many other functions\r\n\r\n\t// async qqw() {      // < --haven't type check\r\n\t// \treturn ''\r\n\t// }\r\n}\r\n//  ... and many many other objects: post, photo, group, ...\r\n```\r\n\r\ntest with bad function qqw():string\r\nmake err mess `Promise<string> != Promise<Resp>`\r\n```ts\r\nlet user: router = {\r\n\tasync qwa() {\r\n\t\treturn new Resp\r\n\t},\r\n\t// async qqw() {      // < --make err mess Promise<string> != Promise<Resp>\r\n\t// \treturn ''\r\n\t// }\r\n}\r\n```\r\n\r\n__type check__ work with object and it is good\r\nbut.\r\nreal example.\r\nin context `typeorm` + `routing-controllers` need use classes to decorate it\r\n\r\nexample https://github.com/typestack/routing-controllers#return-promises\r\n```\r\n@JsonController()\r\nexport class UserController {\r\n\r\n    @Get(\"/users\")\r\n    getAll() {\r\n       return userRepository.findAll();\r\n    }\r\n\r\n    @Get(\"/users/:id\")\r\n    getOne(@Param(\"id\") id: number) {\r\n       return userRepository.findById(id);\r\n    }\r\n\r\n    @Post(\"/users\")\r\n    post(@Body() user: User) {\r\n       return userRepository.insert(user);\r\n    }\r\n\r\n    @Put(\"/users/:id\")\r\n    put(@Param(\"id\") id: number, @Body() user: User) {\r\n       return userRepository.updateById(id, user);\r\n    }\r\n\r\n    @Delete(\"/users/:id\")\r\n    remove(@Param(\"id\") id: number) {\r\n       return userRepository.removeById(id);\r\n    }\r\n\r\n}\r\n```"}}
{"actor":{"display_login":"qwabra"}}