Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions fixtures/components/complex-types/button/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import * as React from 'react';

export interface ButtonProps {
style: ButtonProps.Style;
}

export namespace ButtonProps {
export interface Style {
root?: {
background?: {
active?: string;
default?: string;
disabled?: string;
hover?: string;
};
color?: {
active?: string;
default?: string;
disabled?: string;
hover?: string;
};
borderColor?: {
active?: string;
default?: string;
disabled?: string;
hover?: string;
};
};
}
}

export default function Button(props: ButtonProps) {

Check warning on line 34 in fixtures/components/complex-types/button/index.tsx

View workflow job for this annotation

GitHub Actions / build / build

Missing return type on function

Check warning on line 34 in fixtures/components/complex-types/button/index.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Build documenter

Missing return type on function
return <div style={{ background: props.style.root?.background?.default }} />;
}
39 changes: 21 additions & 18 deletions src/components/object-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,27 @@ export function getObjectDefinition(
return getUnionTypeDefinition(realTypeName, realType, rawTypeNode, checker);
}
if (realType.getProperties().length > 0) {
return {
type: type,
inlineType: {
name: realTypeName,
type: 'object',
properties: realType
.getProperties()
.map(prop => {
const propType = checker.getTypeAtLocation(extractDeclaration(prop));
return {
name: prop.getName(),
type: stringifyType(propType, checker),
optional: isOptional(propType),
};
})
.sort((a, b) => a.name.localeCompare(b.name)),
},
};
const properties = realType
.getProperties()
.map(prop => {
const propType = checker.getTypeAtLocation(extractDeclaration(prop));
return {
name: prop.getName(),
type: stringifyType(propType, checker),
optional: isOptional(propType),
};
})
.sort((a, b) => a.name.localeCompare(b.name));
if (properties.every(prop => prop.type.length < 200)) {
return {
type: type,
inlineType: {
name: realTypeName,
type: 'object',
properties: properties,
},
};
}
}
if (realType.getCallSignatures().length > 0) {
if (realType.getCallSignatures().length > 1) {
Expand Down
15 changes: 13 additions & 2 deletions test/components/complex-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import { expect, test, beforeAll } from 'vitest';
import { ComponentDefinition } from '../../src/components/interfaces';
import { buildProject } from './test-helpers';

let button: ComponentDefinition;
let buttonGroup: ComponentDefinition;
let sideNavigation: ComponentDefinition;
let columnLayout: ComponentDefinition;
let table: ComponentDefinition;

beforeAll(() => {
const result = buildProject('complex-types');
expect(result).toHaveLength(4);
expect(result).toHaveLength(5);

[buttonGroup, columnLayout, sideNavigation, table] = result;
[button, buttonGroup, columnLayout, sideNavigation, table] = result;
});

test('should have camel and dash-cased names', () => {
Expand Down Expand Up @@ -193,3 +194,13 @@ test('should parse string literal type as single-value union', () => {
},
]);
});

test('should trim long inline types', () => {
expect(button.properties).toEqual([
{
name: 'style',
type: 'ButtonProps.Style',
optional: false,
},
]);
});
Loading