I am trying to write a compact typescript definition file, but I am having troubles doing so for a larger project.
My project has lots of interfaces that are implemented by a number of classes.
From what I can see I always need to re"implement"/redeclare the methods of the interfaces in the classes like so:
declare module someModule {
interface InterfaceOne {
/**
* Some lengthy description
*/
someStuff():any;
/**
* Some lengthy description
*/
moreStuff():any;
}
class OneClass implements InterfaceOne {
/**
* Some lengthy description
*/
someStuff():any;
/**
* Some lengthy description
*/
moreStuff():any;
/**
* Even more description
*/
classStuff(): any;
}
class TwoClass implements InterfaceOne {
/**
* Some lengthy description
*/
someStuff():any;
/**
* Some lengthy description
*/
moreStuff():any;
/**
* Even more description
*/
classStuff(): any;
}
}
If I leave out the someStuff
and moreStuff
declarations from the interfaces
I get this error:
error TS2137: Class TwoClass declares interface InterfaceOne but does not implement it:
So I always need to copy all of the declarations to each and every class that implements the interface.
Is there some way around that? Why do I need to do that? Is there any good reason for having to copy the combined contents of all interfaces to the class bodies in a library declaration file? It's a declaration only, not the implementation, so why isn't my declaration implements InterfaceOne
enough already? I don't need to copy all base type members from a super type to an extending type, either, so why is this different for interfaces?
In the library that I am writing the definition file for these interfaces are actually mixins so in the end my definition file actually gets longer than the original implementation that has the bodies!
Edit: After posting I found this answer - so my question is likely to be a duplicate, although the other question is for a far older version of Typescript.
Edit: I realize this may not be the correct place to discuss this and I am thinking about deleting this question. For reference, I asked the question in this official typescript issue.