Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

Plan: Check for external type on model property

  • Understand the codebase and existing tests
  • Add validation in $alternateType decorator to check when external type is used on ModelProperty
  • Add diagnostic message for this case
  • Add test cases to verify the warning is reported
  • Add changelog entry
  • Update decorator documentation
  • Request code review

Summary

This PR adds a warning when @alternateType decorator with external type information is applied to model properties.

Problem: According to the issue, using @@alternateType(FieldWithExternalType.name, { identity: "crate::models::HandWrittenType" }, "rust") doesn't work and should warn the user.

Solution: Added validation in the $alternateType decorator that:

  1. Checks if the source is a ModelProperty
  2. Checks if the alternate type is an external type (has identity property)
  3. Reports a warning with code external-type-on-model-property
  4. Returns early to prevent setting the invalid decorator data

Changes:

  1. src/lib.ts: Added new diagnostic message "external-type-on-model-property"
  2. src/decorators.ts: Added validation check in $alternateType decorator before processing external types
  3. test/decorators/alternate-type.test.ts: Added test case to verify the warning is correctly reported
  4. .chronus/changes/: Added changelog entry
  5. lib/decorators.tsp: Updated decorator documentation with important note and invalid/valid examples
  6. website/.../decorators.md: Updated generated documentation in website

Test: Added test case should warn when external type is applied to model property that verifies:

  • The diagnostic is raised when external type info is used on a model property
  • The diagnostic code is external-type-on-model-property

Documentation Updates:

  • Added Important note stating external types cannot be applied to model properties
  • Added example showing invalid usage with warning comment
  • Added example showing correct usage (applying to type definition)

Note: External types should be applied to the type definition itself (Scalar, Model, Enum, or Union) instead of model properties, as shown in the existing external type tests.

Code Review: ✅ No issues found

Original prompt

This section details on the original issue you should resolve

<issue_title>[TCGC] Check for external type</issue_title>
<issue_description>TCGC needs to report warning when @alternateType with external type info is decorated on model property. See playground here.

@@alternateType(FieldWithExternalType.name,
  {
    identity: "crate::models::HandWrittenType",
  },
  "rust"
);

The above usage could not work. TCGC needs to report warning.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 16, 2026 01:57
- Added diagnostic "external-type-on-model-property" in lib.ts
- Added validation in $alternateType decorator to check if source is ModelProperty with external type
- Added test case to verify warning is reported
- External type on model properties is not supported and should warn users

Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
Copilot AI changed the title [WIP] Add warning for external type with alternateType [TCGC] Warn when @alternateType with external type is applied to model property Jan 16, 2026
Copilot AI requested a review from tadelesh January 16, 2026 02:01
@tadelesh tadelesh marked this pull request as ready for review January 16, 2026 02:19
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 16, 2026

Open in StackBlitz

npm i https://pkg.pr.new/Azure/typespec-azure/@azure-tools/typespec-client-generator-core@3784

commit: 4fa225b

@tadelesh
Copy link
Member

@copilot Please also update the doc for this decorator and use pnpm run regen-docs to regen the decorator doc in website.

- Added important note about external types not being applicable to model properties
- Added example showing invalid usage (external type on model property)
- Added example showing correct usage (external type on type definition)
- Updated both decorators.tsp and generated docs in website

Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 19, 2026

@copilot Please also update the doc for this decorator and use pnpm run regen-docs to regen the decorator doc in website.

Updated the decorator documentation in both lib/decorators.tsp and the website. Added an important note about external types not being applicable to model properties, along with an example showing invalid usage and the correct approach. Commit: bf49d66

@microsoft-github-policy-service microsoft-github-policy-service bot added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TCGC] Check for external type

2 participants