Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: interface statement can have decorators #5202

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/spec/src/spec.emu.html
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ <h1>Syntactic Grammar</h1>
`...` ReferenceExpression

InterfaceStatement :
`interface` Identifier TemplateParameters? InterfaceHeritage? `{` InterfaceBody? `}`
DecoratorList? `interface` Identifier TemplateParameters? InterfaceHeritage? `{` InterfaceBody? `}`

InterfaceHeritage :
`extends` ReferenceExpressionList;
Expand Down
13 changes: 12 additions & 1 deletion website/src/content/docs/docs/language-basics/decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ title: Decorators

Decorators in TypeSpec allow developers to attach metadata to types within a TypeSpec program. They can also be used to compute types based on their inputs. Decorators form the core of TypeSpec's extensibility, providing the flexibility to describe a wide variety of APIs and associated metadata such as documentation, constraints, samples, and more.

A range of TypeSpec constructs can be decorated, including [namespaces](./namespaces.md), [operations](./operations.md) and their parameters, and [models](./models.md) and their members.
Various elements of TypeSpec can be decorated.
Examples include the following,

* [enums](./enums.md)
* [interfaces](./interfaces.md)
* [models](./models.md)
* [namespaces](./namespaces.md)
* [operations](./operations.md)
* [scalar](./scalars.md)
* [unions](./unions.md)

and their parameters or members.

Decorators are defined using JavaScript functions that are exported from a standard ECMAScript module. When a JavaScript file is imported, TypeSpec will look for any exported functions prefixed with `$`, and make them available as decorators within the TypeSpec syntax. When a decorated declaration is evaluated by TypeSpec, the decorator function is invoked, passing along a reference to the current compilation, an object representing the type it is attached to, and any arguments the user provided to the decorator.

Expand Down