Typescript default function inside interface

It works

interface test{
    imp():number;
}

but you can implement the function inside.

interface test{
    imp():number{
      // do something if it is not overwritten
    }
}

This does not work in typescript for me, but there may be some kind of reserved word, for example, by default or the like, to implement a function inside the interface that is not overwritten if the work by default works.

+4
source share
1 answer

No. TypeScript Interfaces are not accessible at runtime, i.e. they are completely absent in the generated JavaScript.

Perhaps you wanted to use class:

class Test{
    imp(){return 123}
 }
+4
source

All Articles