refactor: extract shared LengthStrategy type - #3940
Conversation
✅ Deploy Preview for fakerjs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #3940 +/- ##
=======================================
Coverage 98.91% 98.91%
=======================================
Files 924 925 +1
Lines 3224 3230 +6
Branches 567 567
=======================================
+ Hits 3189 3195 +6
Misses 31 31
Partials 4 4
🚀 New features to boost your workflow:
|
|
I will add the docs here when #3939 got merged, to not fall into to many merge conflicts |
I have added a preview link for ease of verifcation. |
e802502 to
f476ad6
Compare
|
Should we add a Types page? |
If so, it needs clickable links from the method docs. But then you might loose the context / back history and get lost. How about hover tooltips? But these might introduce problems with mobile device docs. 🤔 Do you have further ideas? |
|
Use the shadow type system and add the description as hoverable text. |
6640166 to
3cbd7c7
Compare
There was a problem hiding this comment.
Pull request overview
This PR centralizes the “length mismatch handling” strategy into a shared LengthStrategy/LengthStrategyType in src/utils/types.ts, updates Lorem/Word APIs to use the shared type, and enhances the API docs generator/UI to preserve per-union-member documentation via “shadow type” popovers.
Changes:
- Introduces
LengthStrategy+LengthStrategyTypeinsrc/utils/types.tsand re-exports them fromsrc/index.ts. - Updates
word/loremmodules (andfilterWordListByLength) to useLengthStrategyTypeinstead of repeating the string-literal union. - Extends API docs processing/output to extract enum-member JSDoc for template-literal “shadow types” and render per-value descriptions as popovers (with snapshot/test coverage).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/scripts/apidocs/method.example.ts | Adds a shadow-type test fixture (enum + template-literal alias + method). |
| test/scripts/apidocs/snapshots/method.spec.ts.snap | Updates snapshots to include the new method/type rendering expectations. |
| src/utils/types.ts | Adds shared LengthStrategy enum and LengthStrategyType alias. |
| src/modules/word/module.ts | Replaces repeated strategy unions with LengthStrategyType across Word APIs. |
| src/modules/word/filter-word-list-by-length.ts | Uses LengthStrategyType for the strategy option. |
| src/modules/lorem/module.ts | Uses LengthStrategyType for the strategy option. |
| src/index.ts | Re-exports LengthStrategy and LengthStrategyType. |
| scripts/apidocs/processing/type.ts | Adds shadow-type description extraction + attachment to type members. |
| scripts/apidocs/processing/parameter.ts | Enriches parameter types with per-value descriptions based on syntactic type nodes. |
| scripts/apidocs/output/page.ts | Renders parameter types as HTML (with popover triggers for described members). |
| docs/.vitepress/components/api-docs/method.ts | Clarifies type is HTML. |
| docs/.vitepress/components/api-docs/method-parameters.vue | Switches type column to v-html and adds popover styling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
This is a good addition. I'm not sure about the font-family and how the descriptions gets added to the types, but the rest looks good to me.
During review I noticed, that this applies to LengthStrategy and SexType, but not ColorFormats. Which made me think what would be better and consistent UX.
Keep the named type, then show the values+descriptions on hover/popover or explode the enum/union types (as is).
There was a problem hiding this comment.
Since the remaining things will be handled in a separate PR, I approve this.
- Discussion: Do we show the enum type values directly or do we show an popover with more details. aka do we give the user a hint that the wrapper type + actual enum exist or should they read that from the signature?
- Inline: Read the enum value description at type creation time, instead of retroactively attaching it.
25981a0 to
1a5d489
Compare
|
There appears to be merge conflicts. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: ST-DDT <ST-DDT@gmx.de>
1a5d489 to
8047b4b
Compare
8047b4b to
9330894
Compare





related to #1443
Preview: