Interfaces
Interfaces are useful for grouping and reusing operations.
You can declare interfaces using the interface
keyword. Its name must be an identifier
.
interface SampleInterface { foo(): int32; bar(): string;}
Composing interfaces
You can use the extends
keyword to incorporate operations from other interfaces into a new interface.
Consider the following interfaces:
interface A { a(): string;}
interface B { b(): string;}
You can create a new interface C
that includes all operations from A
and B
:
interface C extends A, B { c(): string;}
This is equivalent to:
interface C { a(): string; b(): string; c(): string;}
Interface templates
Interfaces can be templated. For more details on templates, see templates.
interface ReadWrite<T> { read(): T; write(t: T): void;}
Templating interface operations
Operations defined within an interface can also be templated. For more details on templates, see templates.
interface ReadWrite<T> { read(): T; write<R>(t: T): R;}
alias MyReadWrite = ReadWrite<string>;
op myWrite is MyReadWrite.write<int32>;