Skip to content

Fix ProxyGenerator type ordering for property type annotation forward references#2192

Merged
einari merged 4 commits into
mainfrom
fix/proxy-generator-type-annotation-ordering
May 4, 2026
Merged

Fix ProxyGenerator type ordering for property type annotation forward references#2192
einari merged 4 commits into
mainfrom
fix/proxy-generator-type-annotation-ordering

Conversation

@einari
Copy link
Copy Markdown
Contributor

@einari einari commented May 4, 2026

Fixed

  • ReferenceError: Cannot access '...' before initialization in combined generated TypeScript files when a property uses @field(String) but its type annotation references another generated class (e.g. all!: FromEveryDefinition). TypeScript's emitDecoratorMetadata emits __metadata("design:type", T) based on the declared type annotation, not the @field argument — so the referenced class must appear earlier in the file.

…rom property type annotation

TypeScript's emitDecoratorMetadata emits __metadata("design:type", T) using the
declared property type annotation, not the argument passed to @field. So a property
like `@field(String) all!: FromEveryDefinition` creates a runtime reference to
FromEveryDefinition at class-definition time, causing a "Cannot access before
initialization" error when the class appears later in the same combined file.

Extend TopologicallySortBodies to also scan `!:` and `?:` property type annotations
(in addition to @field decorator arguments) when building the dependency graph for
topological ordering.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@einari einari added the patch label May 4, 2026
Comment thread Source/DotNET/Tools/ProxyGenerator/TypeScriptContentCombiner.cs Fixed
Copy link
Copy Markdown
Contributor Author

@einari einari left a comment

Choose a reason for hiding this comment

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

@copilot See the code review and implement as suggested; #2192 (review)

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

@copilot See the code review and implement as suggested; #2192 (review)

Applied the suggested refactor in commit 2cad7f7 — both the fieldPattern and annotationPattern foreach loops now use .Select(match => match.Groups["type"].Value) to project directly in the iteration variable, eliminating the intermediate typeName assignment inside the loop body.

Comment thread Source/DotNET/Tools/ProxyGenerator/TypeScriptContentCombiner.cs Fixed
Copilot finished work on behalf of einari May 4, 2026 17:08
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@einari einari merged commit 9e918f5 into main May 4, 2026
50 checks passed
@einari einari deleted the fix/proxy-generator-type-annotation-ordering branch May 4, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants