microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
bead6d153df3e7bd00100e72ae51a740bba955e6

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

docs/language-basics/interfaces.md

62lines · modepreview

---
id: interfaces
title: Interfaces
---

# Interfaces

Interfaces can be used to group and reuse [operations](./operations.md).

Interfaces are declared using the `interface` keyword.

```cadl
interface SampleInterface {
  foo(): int32;
  bar(): string;
}
```

## Composing interfaces

The keyword `extends` can be used to compose operations from other interfaces into a new interface.

Given the following interfaces

```cadl
interface A {
  a(): string;
}

interface B {
  b(): string;
}
```

a new interface `C` can be created including all operations from `A` and `B`

```cadl
interface C extends A, B {
  c(): string;
}
```

which is equivalent to

```cadl
interface C {
  a(): string;
  b(): string;
  c(): string;
}
```

## Interface template

Interfaces can be templated, [see templates](./templates.md) for details on templates.

```cadl
interface ReadWrite<T> {
  read(): T;
  write(t: T): void;
}
```