Skip to content

Comments

Copilot/add expression decorations#9747

Draft
johanste wants to merge 6 commits intomicrosoft:mainfrom
johanste:copilot/add-decorators-support
Draft

Copilot/add expression decorations#9747
johanste wants to merge 6 commits intomicrosoft:mainfrom
johanste:copilot/add-decorators-support

Conversation

@johanste
Copy link
Contributor

@johanste johanste commented Feb 19, 2026

Decorating expressions

Decorators can be applied to inline model expressions and other type expressions used in property types, aliases, and is/extends clauses. Place the decorator before the expression:

model Pet {
  owner: @doc("Owner contact info") {
    name: string;
    phone: string;
  };
}
alias Address = @doc("A mailing address") {
  street: string;
  city: string;
};

Copilot AI and others added 6 commits February 19, 2026 02:48
…ter support

Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
…ge; add tests

Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
…decorated expressions

Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
…ting ones

Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
…ample snapshot

Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service bot added compiler:core Issues for @typespec/compiler meta:website TypeSpec.io updates labels Feb 19, 2026
@johanste johanste changed the title Copilot/add decorators support Copilot/add expression decorations Feb 19, 2026
@github-actions
Copy link
Contributor

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - feature ✏️

Add support for decorating type expressions. Decorators can now be applied to inline models, type references, union expressions, and is/extends targets.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 19, 2026

Open in StackBlitz

npm i https://pkg.pr.new/microsoft/typespec/@typespec/compiler@9747

commit: 0c8359a

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Copy link
Member

@witemple-msft witemple-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is potentially a big problem to allow decorating type references. The implementation in this PR will allow you to overwrite metadata without controlling the original declaration.

https://cadlplayground.z22.web.core.windows.net/prs/9747/?e=%40typespec%2Fopenapi3&c=QGRvYygiMSIpCm1vZGVsIFgge30KxwxZIHsKICB4OiDGJTIiKSBYOwp9&options=%7B%7D&vs=%7B%7D

It seems like we only want to allow decorating type literals, i.e. expressions that create unique instances of a Type.

I'm also a little concerned about the union case. We have potentially a lot of code that assumes that a union can only be decorated if it is a named declaration. We do not even allow augmentations like:

alias A = string | int32;

@@doc(A, "Example");
      ~ > error augment-decorator-target: Cannot augment union expressions.

If the other PR allowing named model expressions lands, then I would support allowing decorating type expressions that start with a keyword: @doc("Example") model { ... }, @dec union { string, int32 }, etc.

@timotheeguerin
Copy link
Member

yeah we did talk about this might be the only way to allow inline decorator was when using the keyword form of expressions. I also feel like from a quick look that while it does seem to pass the test I don't think copilot really did the change correctly, I don't think we need a new Decorator node in the tree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants