I just want to declare a static property in typescript interface? I have not found anywhere regarding this.
interface myInterface {
static
I implemented a solution like Kamil Szot's, and it has an undesired effect. I have not enough reputation to post this as a comment, so I post it here in case someone is trying that solution and reads this.
The solution is:
interface MyInterface {
Name: string;
}
const MyClass = class {
static Name: string;
};
However, using a class expression doesn't allow me to use MyClass
as a type. If I write something like:
const myInstance: MyClass;
myInstance
turns out to be of type any
, and my editor shows the following error:
'MyClass' refers to a value, but is being used as a type here. Did you mean 'typeof MyClass'?ts(2749)
I end up losing a more important typing than the one I wanted to achieve with the interface for the static part of the class.
Val's solution using a decorator avoids this pitfall.