{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2000","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2000/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2000/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2000/events","html_url":"https://github.com/Microsoft/TypeScript/issues/2000","id":57163701,"number":2000,"title":"Support override keyword on class methods","user":{"login":"rwyborn","id":10917360,"avatar_url":"https://avatars.githubusercontent.com/u/10917360?v=3","gravatar_id":"","url":"https://api.github.com/users/rwyborn","html_url":"https://github.com/rwyborn","followers_url":"https://api.github.com/users/rwyborn/followers","following_url":"https://api.github.com/users/rwyborn/following{/other_user}","gists_url":"https://api.github.com/users/rwyborn/gists{/gist_id}","starred_url":"https://api.github.com/users/rwyborn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rwyborn/subscriptions","organizations_url":"https://api.github.com/users/rwyborn/orgs","repos_url":"https://api.github.com/users/rwyborn/repos","events_url":"https://api.github.com/users/rwyborn/events{/privacy}","received_events_url":"https://api.github.com/users/rwyborn/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Declined","name":"Declined","color":"556677"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Suggestion","name":"Suggestion","color":"006b75"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-02-10T11:40:10Z","updated_at":"2015-05-05T06:09:13Z","closed_at":"2015-05-04T22:38:35Z","body":"(NOTE, this is *not* a duplicate of Issue #1524. The proposal here is more along the lines of the C++ override specifier, which makes much more sense for typescript)\r\n\r\nAn override keyword would be immensely useful in typescript. It would be an optional keyword on any method that overrides a super class method, and similar to the override specifier in C++ would indicate an intent that \"*the name+signature of this method should always match the name+signature of a super class method*\". This catches a whole range of issues in larger code bases that can otherwise be easily missed. \r\n\r\nAgain similar to C++, *it is not an error to omit the override keyword from an overridden method*. In this case the compiler just acts exactly as it currently does, and skips the extra compile time checks associated with the override keyword. This allows for the more complex untyped javascript scenarios where the derived class override does not exactly match the signature of the base class.\r\n\r\n## Example use\r\n```typescript\r\nclass Animal {\r\n    move(meters:number):void {\r\n    }\r\n}\r\n\r\nclass Snake extends Animal {\r\n    override move(meters:number):void {\r\n    }\r\n}\r\n```\r\n## Example compile error conditions\r\n```typescript\r\n// Add an additional param to move, unaware that the intent was \r\n// to override a specific signature in the base class\r\nclass Snake extends Animal {\r\n    override move(meters:number, height:number):void {\r\n    }\r\n}\r\n// COMPILE ERROR: Snake super does not define move(meters:number,height:number):void\r\n\r\n// Rename the function in the base class, unaware that a derived class\r\n// existed that was overriding the same method and hence it needs renaming as well\r\nclass Animal {\r\n    megamove(meters:number):void {\r\n    }\r\n}\r\n// COMPILE ERROR: Snake super does not define move(meters:number):void\r\n\r\n// Require the function to now return a bool, unaware that a derived class\r\n// existed that was still using void, and hence it needs updating\r\nclass Animal {\r\n    move(meters:number):bool {\r\n    }\r\n}\r\n// COMPILE ERROR: Snake super does not define move(meters:number):void\r\n```\r\n## IntelliSense\r\nAs well as additional compile time validation, the override keyword provides a mechanism for typescript intellisense to easily display and select available super methods, where the intent is to specifically override one of them in a derived class. Currently this is very clunky and involves browsing through the super class chain, finding the method you want to override, and then copy pasting it in to the derived class to guarantee the signatures match.\r\n\r\n### Proposed IntelliSense mechanism\r\nWithin a class declaration:\r\n1. type override\r\n2. An auto complete drop down appears of all super methods for the class\r\n3. A method is selected in the drop down\r\n4. The signature for the method is emitted into the class declaration after the override keyword.\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/98964979","html_url":"https://github.com/Microsoft/TypeScript/issues/2000#issuecomment-98964979","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2000","id":98964979,"user":{"login":"hdachev","id":304875,"avatar_url":"https://avatars.githubusercontent.com/u/304875?v=3","gravatar_id":"","url":"https://api.github.com/users/hdachev","html_url":"https://github.com/hdachev","followers_url":"https://api.github.com/users/hdachev/followers","following_url":"https://api.github.com/users/hdachev/following{/other_user}","gists_url":"https://api.github.com/users/hdachev/gists{/gist_id}","starred_url":"https://api.github.com/users/hdachev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hdachev/subscriptions","organizations_url":"https://api.github.com/users/hdachev/orgs","repos_url":"https://api.github.com/users/hdachev/repos","events_url":"https://api.github.com/users/hdachev/events{/privacy}","received_events_url":"https://api.github.com/users/hdachev/received_events","type":"User","site_admin":false},"created_at":"2015-05-05T06:09:13Z","updated_at":"2015-05-05T06:09:13Z","body":"Please excuse the whining, but honestly, while your argument does apply to the `public` keyword in a language where everything is public by default, quite world dividing indeed, having things like `abstract` and an optional `override` keyword will simply help developers feel safer, make less mistakes and waste less time.\r\n\r\nOverriding is one of the few remaining highly-typo-sensitive aspects of the language, because a mistyped overriding method name is not an obvious compile time problem. The benefit of `override` is obvious, as it you allows you to state your intention to override - if the base method doesn't exist its a compile time error. All hail the type system. Why would anyone not want this?"}}