Repository navigation
Generate the README API reference from JSDoc - #4224
amanmahajan7 wants to merge 24 commits into
Conversation
Make the JSDoc comments the single source of the API documentation: the README's API reference is generated from them, so the docs no longer have to be kept in sync by hand. - Move the API reference text of the README into the JSDoc comments of the exports, keeping the README's wording - Add `vp run docs`, which generates the API reference with TypeDoc and typedoc-plugin-markdown between the `api:start` and `api:end` markers of the README - `vp run ci` fails if the generated README is out of date - TypeDoc does not support TypeScript 7 yet, so it runs with `@typescript/typescript6` while the `typescript` package stays on TypeScript 7 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Enable oxlint's `jsdoc` plugin, now that JSDoc comments are the source of the README's API reference. TypeDoc's tags are allowed by `jsdoc/check-tag-names`, and `@defaultValue` is preferred over `@default`. The rules that require types in comments are disabled, as TypeScript provides them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reduce the repetition of the generated API reference: - Remove the type parameter and parameter sections, which repeat the signatures and the "Generics" section - List the properties of interfaces in a table, unless a property has more than a short description - Only show the return type of functions with a `@returns` description - Remove the "Inherited from" and "Overrides" sections - Don't copy the comments of the members that `CalculatedColumn` redeclares Make the generator stricter: - Links from the hand-written README sections use the member they link to as link title, e.g. "Column.width", to keep their anchor up to date - Fail on links and anchors that don't match a heading - Use `github-slugger` for the heading anchors - Detect code fences by their character and length Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use the same type parameter names as the other types, which simplifies the "Generics" section of the README. Type parameter names are not part of the public API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Members that come from a public type through an internal type, like the cell event handlers that `RenderCellProps` inherits from `BaseRenderCellProps`, which picks them from `DataGridProps`, repeated the docs of the public type. Remove them like the members inherited directly from public types, and remove the properties sections left empty, like the one of `RenderSortStatusProps`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TypeDoc names destructured parameters `__namedParameters`, which showed in the signatures of the components and render functions that destructure their props, e.g. `SelectCheckbox`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4224 +/- ##
=======================================
Coverage 99.13% 99.13%
=======================================
Files 46 46
Lines 2207 2207
Branches 977 977
=======================================
Hits 2188 2188
Misses 19 19
🚀 New features to boost your workflow:
|
- Title components like the previous README, e.g. `<DataGrid />` instead of `DataGrid()`, and show their props instead of a function signature - List the components with a props interface first, each followed by its props interface, then the other components Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| } from './style/core'; | ||
| import SummaryRow from './SummaryRow'; | ||
|
|
||
| /** |
There was a problem hiding this comment.
This file has become quite big. We can create a separate interface file if needed
There was a problem hiding this comment.
I was thinking of moving a bunch of types into types.ts so we can manage all of them together/have better type inheritance & maintenance.
| - `SR`: Summary row type | ||
| - `K`: Row key type | ||
|
|
||
| <!-- api:start --> |
There was a problem hiding this comment.
Can create a separate API.md file if needed
Install TypeScript 6 as `typescript` and TypeScript 7 as `@typescript/native`, the setup recommended for tools that need the TypeScript API, which TypeScript 7 doesn't provide yet. TypeScript 6's package also provides a `tsc` binary, which npm linked instead of TypeScript 7's, so `vp run typecheck` used TypeScript 6. With this setup, `tsc` is TypeScript 7, and TypeDoc no longer needs a resolve hook, a peer dependency override, or `skipLibCheck`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nstepien
left a comment
There was a problem hiding this comment.
Not sure I like the approach.
Now we have a huge script we have to maintain, and we have to compromise on how typescript is installed.
Are there alternative tools to generate JSDocs?
The new output is honestly much less user-friendly, it's more confusing to read, you can't just copy/paste it for example:
Before:
Another example:
This is just hard to read:
Let me read TypeScript with syntax highlighting, not... this 🥺🙏
What do you think?
We can keep some of the generated JSDocs though.
| * :bulb: While optional, setting this prop is recommended for optimal performance, as the returned value is used to set the `key` prop on the row elements. | ||
| * | ||
| * :warning: **Performance:** Define this function outside your component or memoize it with `useCallback` to prevent unnecessary re-renders. |
There was a problem hiding this comment.
:bulb: and :warning: are GH-flavored markdown stuff, what do these look like in vscode?
There was a problem hiding this comment.
The :warning: and :bulb: shortcodes are now
Had to add the script otherwise Typedoc defaults are not the best
Don't think this should be an issue. Looks like TS7 support is on the way TypeStrong/typedoc#3098 (comment)
I agree, I wasn't a big fan either
I have an idea in mind. I will give it a try I do think it is better to have single source of truth. Claude found the following items Drift between the README and the JSDoc before this PRCompared on Defaults only in the README (the editor showed no default):
Same prop, different descriptions:
Behavior documented only in the README (missing from editor hovers):
No JSDoc at all (only documented in the README):
No README section:
|
Replace TypeDoc and `typedoc-plugin-markdown` with a smaller generator that parses the declarations and JSDoc comments of `lib/index.d.ts`, which `vp pack` bundles with TypeScript 7, using `oxc-parser`: - Only TypeScript 7 is needed again, as the generator doesn't rely on the TypeScript API - Types are shown as copyable declarations with their comments, like the previous README, instead of tables - The layout and labels follow the previous README Also replace the `:warning:` and `:bulb:` emoji shortcodes with emoji, as editors don't render shortcodes in hovers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- List the items in the order they are exported from `src/index.ts`, which now exports them by name, in the order of the previous README - Title the items and members with their signatures, which keeps most of the previous anchors, and nest the props interfaces under their components - Show the documented internal types with the other types, and the undocumented ones in the code block of the types that reference them - Declare the `div` props of `DataGridProps` with React's types - Move the "Generics" section back to the end of the API reference Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Title the items and members with their name, and show their signature in a code block, so their anchors don't change with their types - Show `DataGridRenderersContext` like the other constants - Only show the helper types directly referenced by a type Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…reference Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gs, and headings in JSDoc Also describe the props of SelectCheckbox under Props again, and run `vp run docs` in place of `vp pack` in the ci task. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@nstepien wdyt about the new approach (desc updated). It does not use typedoc anymore. We still need the script but hopefully we do not need to change it often. Output is closed to before with some changes (mentioned in the PR). |
|
another idea, I can just use ts7 beta api |
…arser Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # README.md # src/types.ts
…group` tags Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… cases Render `@see Foo` as a link, check the links in the comments of code blocks, catch setext headings in JSDoc, fail on interfaces with a heading per member that extend undocumented types, and only show object types as nested options through `Maybe<…>` and unions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # README.md # src/types.ts
# Conflicts: # README.md # src/TreeDataGrid.tsx
# Conflicts: # README.md # src/types.ts





Generate the README API reference from JSDoc
The README's API reference and the JSDoc comments documented the same API twice, and they had drifted apart (see below). This PR makes the JSDoc comments the single source: the API reference section of the README is generated from them, and CI fails if it is out of date. Editor hovers now also show the full docs, including examples, defaults, and performance notes.
Approach
**Default:**→@defaultValue**Example:**→@example**See also:**→@see**Returns:**→@returns@typeParam{@linkcode}vp run docsrunsvp pack, thenscripts/generateApiDocs.ts, thenvp fmt README.md. The script parses the declarations and JSDoc comments of the builtlib/index.d.tswith the TypeScript 7 API (typescript/sync), which ships with thetypescript@betathe repo already uses, and writes the API reference between<!-- api:start -->and<!-- api:end -->..d.ts, the signatures are exactly what users of the package see, e.g. hooks show their real return types.src/index.tssets the layout of the API reference: the exports are listed in their order, under the section of the comment above them (// Components,// Hooks,// Render Functions,// Context,// Other,// Types). The exports are reordered to match the previous README, and the set of exports is unchanged.vp run cirunsvp run docsin place ofvp pack, followed bygit diff --exit-code README.md.{@link Column.widht}, including links in comments shown inside code blocks;@deprecated;The generated README
It keeps the layout of the previous README:
###, items at####, props at#####;**Default:**,**Example:**, and**See also:**labels.Types are shown as copyable declarations, with their comments, in
tsxcode blocks:DataGridProps,TreeDataGridProps, andColumn, whose props have examples, lists, or@seetags, keep a heading per prop, with the prop's signature in a code block.RenderRowPropslists every prop, plusextends Omit<React.ComponentProps<'div'>, 'children'>, Pick<DataGridProps<R, SR>, …>, instead of linking toBaseRenderRowProps→BaseRenderCellProps.Maybe,Position,GroupRow,CellEvent, …) are listed at the end of Types, marked "(internal)", as before.Notable differences from the previous README
mainREADME found:#####rowKeyGetter?instead of `###### `rowKeyGetter?: Maybe<(row: R) => K>, followed by the signature in a code block.ColumnWidthstype is#columnwidths-1), which can shift when headings with the same name are added or removed.#rowkeygetter-mayberow-r--k, will break.[width](#width 'Column.width'), andvp run docskeeps their anchor up to date.:warning:and:bulb:shortcodes are nowonCellKeyDownis an absolute GitHub URL, as relative paths can't be resolved from a JSDoc comment.//comments in types. Comments that aren't JSDoc, like// Always set, …inCalculatedColumn, are dropped by the.d.tsbuild, so they aren't shown. The type's description covers it.ColumnFrozenandTreeDataGridPropsnow have a section.Drift this fixes
Compared on
main, member by member:Column.frozen,resizable,sortable,draggable,sortDescendingFirst.rows,onActivePositionChange,direction,Column.width, andColumn.frozen. The README's wording was kept.columns,rows, the summary rows,rowKeyGetter,rowHeight,rowClass,rowGrouper, andgroupIdGetter. Also behavior notes, e.g. "rowKeyGetteris required for row selection to work".TreeDataGridandTreeDataGridProps;DataGridProps'ref,className,style,role, thearia-*props, and thedata-*props;Column.colSpan;DataGridRenderersContext,SelectColumn, andSELECT_COLUMN_KEY.Source changes
There are no public API changes.
divprops.DataGridPropsdeclares thedivprops it accepts (className,style,role,aria-*,onScroll) with React's types instead ofPick-ing them, so they can carry JSDoc. They are type-identical to before.TRowandTSummaryRoware renamed toRandSR, like the other types. Type parameter names are not part of the public API.src/index.ts. It lists its exports explicitly, under section comments, in README order.JSDoc linting
jsdocplugin is enabled.check-tag-namesallows TSDoc'sdefaultValueandtypeParam. No custom tags are used.@defaultValueis preferred over@default.require-*-typerules are off, since TypeScript provides the types.jsdocformatting is not enabled. It corrupts fenced code blocks in@exampletags (oxc-project/oxc#21549).Other changes
github-slugger, which computes GitHub's heading anchors to resolve the links.tsconfig.node.json: includesscripts/.AGENTS.md: documents the workflow:vp run docs, and never edit the generated section by hand;src/index.tssets the sections and order of the API reference;Testing
vp check, the Markdown lint,vp pack, andvp buildpass, andvp run docsis idempotent.github-slugger.🤖 Generated with Claude Code