You can define the interface as usual:
interface MyInterface { Name:string; }
but you can't just do
class MyClass implements MyInterface { static Name:string;
To express that a class must follow this interface for its static properties, you need to be a little tricky:
var MyClass: MyInterface; MyClass = class { static Name:string;
You can even save the class name, TypeScript (2.0) will not mind:
var MyClass: MyInterface; MyClass = class MyClass { static Name:string;
If you do not want to inherit statically from many interfaces, you will have to merge them into a new one first:
interface NameInterface { Name:string; } interface AddressInterface { Address:string; } interface NameAndAddressInterface extends NameInterface, AddressInterface { } var MyClass: NameAndAddressInterface; MyClass = class MyClass { static Name:string;
Or, if you do not want to name a unified interface, you can do:
interface NameInterface { Name:string; } interface AddressInterface { Address:string; } var MyClass: NameInterface & AddressInterface; MyClass = class MyClass { static Name:string;
Working example
Kamil Szot Oct 12 '16 at 18:45 2016-10-12 18:45
source share