@@ -1043,6 +1043,10 @@ export function transformWithWarnings(
10431043 }
10441044
10451045 const wrapperNames = new Set < string > ( ) ;
1046+ // Track wrappers that have expression `as` values (not just string literals)
1047+ // These need generic polymorphic types to accept component-specific props
1048+ const expressionAsWrapperNames = new Set < string > ( ) ;
1049+
10461050 for ( const [ baseName , children ] of extendedBy . entries ( ) ) {
10471051 const names = [ baseName , ...children ] ;
10481052 const hasPolymorphicUsage = names . some ( ( nm ) => {
@@ -1088,6 +1092,38 @@ export function transformWithWarnings(
10881092 }
10891093 }
10901094
1095+ // Also check for `as` usage on intrinsic styled components
1096+ // (e.g., styled.span with as={animated.span})
1097+ for ( const decl of styledDecls ) {
1098+ if ( decl . base . kind === "intrinsic" && ! wrapperNames . has ( decl . localName ) ) {
1099+ const el = root . find ( j . JSXElement , {
1100+ openingElement : { name : { type : "JSXIdentifier" , name : decl . localName } } ,
1101+ } ) ;
1102+ const asAttrs = el . find ( j . JSXAttribute , { name : { type : "JSXIdentifier" , name : "as" } } ) ;
1103+ const hasAs = asAttrs . size ( ) > 0 ;
1104+ const hasForwardedAs =
1105+ el
1106+ . find ( j . JSXAttribute , {
1107+ name : { type : "JSXIdentifier" , name : "forwardedAs" } ,
1108+ } )
1109+ . size ( ) > 0 ;
1110+ if ( hasAs || hasForwardedAs ) {
1111+ wrapperNames . add ( decl . localName ) ;
1112+ // Check if any `as` value is an expression (not a string literal)
1113+ // e.g., as={animated.span} vs as="a"
1114+ const hasExpressionAs = asAttrs . some ( ( path ) => {
1115+ const value = path . node . value ;
1116+ // JSXExpressionContainer means it's an expression like {animated.span}
1117+ // StringLiteral/Literal means it's a string like "a"
1118+ return value ?. type === "JSXExpressionContainer" ;
1119+ } ) ;
1120+ if ( hasExpressionAs ) {
1121+ expressionAsWrapperNames . add ( decl . localName ) ;
1122+ }
1123+ }
1124+ }
1125+ }
1126+
10911127 for ( const decl of styledDecls ) {
10921128 if ( wrapperNames . has ( decl . localName ) ) {
10931129 decl . needsWrapperComponent = true ;
@@ -1863,6 +1899,7 @@ export function transformWithWarnings(
18631899 filePath : file . path ,
18641900 styledDecls,
18651901 wrapperNames,
1902+ expressionAsWrapperNames,
18661903 patternProp,
18671904 exportedComponents,
18681905 stylesIdentifier,
0 commit comments