Skip to content

Conversation

@just-boris
Copy link
Member

Issue #, if available:

Description of changes:

Follow up for this change #76

Make deeply nested inline types properly printed now

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link

codecov bot commented Jul 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.97%. Comparing base (3913223) to head (a55926e).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #82   +/-   ##
=======================================
  Coverage   91.96%   91.97%           
=======================================
  Files          15       15           
  Lines         909      910    +1     
  Branches      265      266    +1     
=======================================
+ Hits          836      837    +1     
  Misses         73       73           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

name: string;
optional: boolean;
type: string;
inlineType?: TypeDefinition;
Copy link
Member Author

Choose a reason for hiding this comment

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

It is recursive now

return {
type: type,
inlineType: {
name: realTypeName.length < 100 ? realTypeName : 'object',
Copy link
Member Author

Choose a reason for hiding this comment

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

If a type is anonymous there will be a string like

{ background?: { active?: string | undefined; default?: string | undefined; disabled?: string | undefined; hover?: string | undefined; } | undefined; color?: { active?: string | undefined; default?: string | undefined; disabled?: string | undefined; hover?: string | undefined; } | undefined; borderColor?: { ...; } |...

We do not need these.

I checked the longest type name in our system is CollectionPreferencesProps.ContentDisplayPreferenceI18nStrings, 62 chars, still below the limit

},
]);
test('should print long inline types', () => {
expect(button.properties).toMatchSnapshot();
Copy link
Member Author

Choose a reason for hiding this comment

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

This type is too long and updating it manually on every change is tedious, let's do a snapshot test

isArrayType(realType) ||
realTypeName === 'HTMLElement'
realTypeName === 'HTMLElement' ||
type === 'React.ReactNode'
Copy link
Member Author

Choose a reason for hiding this comment

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

Prevent React types from expanding into boolean | React.ReactChild | React.ReactFragment | React.ReactPortal

properties: [
{
name: 'content',
optional: true,
Copy link
Member Author

@just-boris just-boris Jul 25, 2025

Choose a reason for hiding this comment

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

A keen reviewer might ask why there is optional: true when the content above does not have a ?

This is happening because undefined is assignable to ReactNode, so {media: undefined} is supported, which makes it technically optional

if (
realType.flags & ts.TypeFlags.String ||
realType.flags & ts.TypeFlags.StringLiteral ||
realType.flags & ts.TypeFlags.Literal ||
Copy link
Member Author

@just-boris just-boris Jul 25, 2025

Choose a reason for hiding this comment

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

Make sure that boolean and number literals do not expand too.

Without this line it generates a type definition like this

{
  "inlineType": {
    "name": "() => boolean",
    "parameters": [],
    "returnType": "boolean",
    "type": "function"
  },
  "name": "valueOf",
  "optional": false,
  "type": "() => boolean"
}

@just-boris just-boris marked this pull request as ready for review July 25, 2025 15:12
@just-boris just-boris requested a review from a team as a code owner July 25, 2025 15:12
@just-boris just-boris requested review from teodoranemes and removed request for a team July 25, 2025 15:12
@just-boris just-boris added this pull request to the merge queue Jul 28, 2025
Merged via the queue into main with commit 26a251e Jul 28, 2025
33 of 35 checks passed
@just-boris just-boris deleted the expand-types branch July 28, 2025 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants