Fix: Props interface not recognized when using 'as' as a prop name#1102
Merged
Princesseuh merged 4 commits intowithastro:mainfrom Feb 18, 2026
Merged
Fix: Props interface not recognized when using 'as' as a prop name#1102Princesseuh merged 4 commits intowithastro:mainfrom
Princesseuh merged 4 commits intowithastro:mainfrom
Conversation
Fixed Props interface being marked as unused when using 'as' as a prop name. The compiler now distinguishes between import aliasing and property destructuring contexts. - Add context checking to prevent false positives - Add test coverage for 'as' prop scenarios
🦋 Changeset detectedLatest commit: d69726a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Member
|
Thank you @jp-knj Can you add some tests? https://github.com/withastro/compiler/blob/main/packages/compiler/test/tsx/props.ts |
5cc7000 to
a7188ba
Compare
Member
Author
|
Thanks, @ematipico |
Princesseuh
reviewed
Feb 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #927
Background
Polymorphic components are a common pattern in modern web development where a component can render as different HTML elements. The as prop is the standard convention for this pattern:
This pattern allows users to create flexible components that can adapt their rendered element based on usage context.
Problem
When using as as a prop name, the Astro compiler fails to recognize that the Props interface is being used, resulting in:
Root Cause
The issue stems from the compiler's Props detection logic (GetPropsType in js_scanner.go). When processing the code, it encounters the as keyword and incorrectly assumes it's part of an import alias pattern (import { Props as Something }), causing it to reset the Props detection.
The compiler didn't distinguish between:
This bug was introduced as a side effect of fixing #814, which added support for Props import aliasing but was too aggressive in its pattern matching.
Changes
Before:
After:
Testing
Docs
Bug fix only - no documentation changes needed. The compiler now correctly handles a previously broken edge case.