I would like to declare an abstract class and a class without declaring that the class implements the abstract class in the same file.
abstract class ExampleAbstractClass {
abstract exampleMethod(): string;
}
class ExampleClass {
exampleMethod(): string { return 'test'; }
}
// I would like to specify that the class does implement the abstract class in another file
ExampleClass implements ExampleAbstractClass
This kind of use case is possible in other languages like Swift with protocols.
Yes, it is possible:
example-class.ts
example-class.test.ts
You'll have to use
interface
alongsideclass
since class declaration merging is currently disallowed in TypeScript. You could also augment the module which defines and implementsExampleClass
in separate files usingdeclare module "<path to implementation source file>" {}
.