'overrides' annotation in typescript

Topics: Language Specification
Apr 4, 2014 at 9:20 AM

I'm greatly enjoying moving to typescript; coming from a strongly-typed background (Java) I like how much the compiler can do for me.

One thing that would be very helpful would be an 'overrides' annotation. In Java, the optional @override annotation tells the compiler that the given function either overrides a superclass's function, or implements an interface function.

For example:
class Animal { 

 public makeSound(): string { return "squeak"; }

class Dog extends Animal { 
  public makeSound(): string { return "woof"; }
The advantage is that the compiler can use this annotation to check for mistakes. If the function claims to override a super implementation, but doesn't, then the coder has probably got the function name wrong. And vice versa; if there is a function which overrides a super, but isn't marked as an override, then that could be a sign that the coder has inadvertently overridden without meaning to.

Does typescript have any annotation support, and are there plans for something like this? It's a real help in maintaining clean code.

Apr 4, 2014 at 2:02 PM
There's already a request for this:
Apr 4, 2014 at 2:09 PM
Hi James,

Agreed, I'll add my vote to yours in that workitem,