Skip to content

Commit

Permalink
fix: Fix handling of specific array types in auto API components
Browse files Browse the repository at this point in the history
- Resolved logic errors when processing fixed-length tuple types such as [number, number].
- Enhanced type inference to ensure accurate handling of array types during component generation.

This update improves the compatibility and stability of auto API components with complex array types.
  • Loading branch information
chiaweilee authored Feb 12, 2025
1 parent ec353be commit 6fc2c62
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/client/theme-default/builtins/API/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,21 @@ const HANDLERS = {
</span>
);
},
array(prop: Extract<PropertySchema, { type: 'array' }>): ReactNode {
array(prop: Extract<PropertySchema, { type: 'array' }> & { items?: any[] }): ReactNode {
let arrayType: ReactNode = <span>any</span>;
if (prop.items) {
if (Array.isArray(prop.items)) return (
<span>
<Token>{'['}</Token>
{prop.items.map((item: Extract<PropertySchema, { type: 'array' }>, i) => (
<span key={`${i}`}>
{i > 0 && ', '}
{this.toNode(item)}
</span>
))}
<Token>{']'}</Token>
</span>
);
const className = this.getValidClassName(prop.items);
arrayType = className ?? this.toNode(prop.items);
}
Expand Down

0 comments on commit 6fc2c62

Please sign in to comment.