{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4171","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4171/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4171/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4171/events","html_url":"https://github.com/Microsoft/TypeScript/issues/4171","id":99309287,"number":4171,"title":"Creating a class whose instances will be instances of Error","user":{"login":"matthewjh","id":489010,"avatar_url":"https://avatars.githubusercontent.com/u/489010?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewjh","html_url":"https://github.com/matthewjh","followers_url":"https://api.github.com/users/matthewjh/followers","following_url":"https://api.github.com/users/matthewjh/following{/other_user}","gists_url":"https://api.github.com/users/matthewjh/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewjh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewjh/subscriptions","organizations_url":"https://api.github.com/users/matthewjh/orgs","repos_url":"https://api.github.com/users/matthewjh/repos","events_url":"https://api.github.com/users/matthewjh/events{/privacy}","received_events_url":"https://api.github.com/users/matthewjh/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Question","name":"Question","color":"d4c5f9"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-08-05T22:05:25Z","updated_at":"2015-08-10T23:39:44Z","closed_at":"2015-08-10T23:39:44Z","body":"Hi,\r\n\r\nI'm creating some custom error classes, but ran into an issue when using jasmine's `expect(fn).toThrowError(MyCustomError);`\r\n\r\nThe problem is that jasmine's `toThrowError` matcher checks that the exception thrown by `fn` is an instance of `Error`. This is clumsy to satisfy in TypeScript, as in `lib.d.ts` `Error` is an interface.\r\n\r\nThus, if one creates `MyCustomError` in the most straightforward and intuitive way supported:\r\n\r\n````javascript\r\nexport class MyCustomError implements Error { \r\n  public name: string = 'MyCustomError';\r\n  public message: string;\r\n}\r\n````\r\n\r\nand throws an instance of this class, code such as that in jasmine that checks for an instance of `Error` will fail. And yet, their assumption seems quite legitimate.\r\n\r\nHere's the code I ended up with:\r\n````javascript\r\nexport class MyCustomError implements Error { \r\n  public name: string = 'MyCustomError';\r\n  public message: string;\r\n}\r\n\r\nMyCustomError.prototype = Object.create(Error.prototype);\r\n````\r\n\r\nThis will satisfy the `instanceof Error` constraint, but it's fairly unintuitive for what seems like a common task (creating a runtime subtype of `Error`) -- one that shouldn't require setting the `prototype` property manually.\r\n\r\nAny thoughts?"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/129647454","html_url":"https://github.com/Microsoft/TypeScript/issues/4171#issuecomment-129647454","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4171","id":129647454,"user":{"login":"mhegazy","id":8000722,"avatar_url":"https://avatars.githubusercontent.com/u/8000722?v=3","gravatar_id":"","url":"https://api.github.com/users/mhegazy","html_url":"https://github.com/mhegazy","followers_url":"https://api.github.com/users/mhegazy/followers","following_url":"https://api.github.com/users/mhegazy/following{/other_user}","gists_url":"https://api.github.com/users/mhegazy/gists{/gist_id}","starred_url":"https://api.github.com/users/mhegazy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhegazy/subscriptions","organizations_url":"https://api.github.com/users/mhegazy/orgs","repos_url":"https://api.github.com/users/mhegazy/repos","events_url":"https://api.github.com/users/mhegazy/events{/privacy}","received_events_url":"https://api.github.com/users/mhegazy/received_events","type":"User","site_admin":false},"created_at":"2015-08-10T23:39:44Z","updated_at":"2015-08-10T23:39:44Z","body":"Looks like the original issue has been answered. please reactivate if you are running into other issues."}}