Skip to content

Type check docs examples #3710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 2, 2023
Merged

Type check docs examples #3710

merged 8 commits into from
Mar 2, 2023

Conversation

devongovett
Copy link
Member

Part of #865

This adds a script that extracts all of the examples from the docs MDX files into TSX files, and then runs TypeScript over them. This will run in CI. It found a number of issues, such as unused variables, missing props, etc. So far, I have only fixed the existing type errors, adding annotations where needed. Eventually, we can add type annotations to all examples.

We may want to eventually have a toggle to switch between TS and JS. For now, only TS is displayed.

@adobe-bot
Copy link

@adobe-bot

This comment was marked as outdated.

@@ -277,53 +277,8 @@ function DropIndicator(props) {

Now that the `DropIndicator` component is implemented, we can render an instance between each item in the list. This uses the `before` drop position by default, except for after the last item in the list.

```tsx example render=false
///- begin collapse -///
function ListBox(props) {
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 was unused. The real implementation is in the below example.


return (
<>
<p>Current tab id: {tabId}</p>
<Tabs aria-label="History of Ancient Rome" items={tabs} onSelectionChange={setTabId}>
<TabList>
{item => (
{(item: Tab) => (
Copy link
Member Author

Choose a reason for hiding this comment

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

These are annoying. Because we designed the API with items on Tabs rather than TabList and TabPanels, this will always be unknown by default without an annotation.

function Example() {
let [selected, setSelected] = React.useState(new Set(['cheese']));
let [selected, setSelected] = React.useState<Selection>(new Set(['cheese']));
Copy link
Member Author

Choose a reason for hiding this comment

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

These are annoying, and caused by onSelectionChange which may emit "all" | Set<Key>, but the type of this variable is only inferred to be Set<string> so it always requires an annotation.

…m into docs-ts

# Conflicts:
#	packages/@adobe/react-spectrum/package.json
#	packages/@adobe/react-spectrum/src/index.ts
#	packages/@react-aria/dnd/src/index.ts
#	packages/@react-aria/overlays/docs/useOverlayTrigger.mdx
#	packages/@react-spectrum/autocomplete/src/SearchAutocomplete.tsx
#	packages/@react-spectrum/list/docs/ListView.mdx
#	packages/dev/parcel-transformer-mdx-docs/MDXTransformer.js
@rspbot
Copy link

rspbot commented Feb 21, 2023

# Conflicts:
#	packages/@adobe/react-spectrum/package.json
#	packages/@react-spectrum/actionbar/docs/ActionBar.mdx
@rspbot
Copy link

rspbot commented Feb 28, 2023

@rspbot
Copy link

rspbot commented Feb 28, 2023

Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

LGTM, verified locally that running make check-examples was catching typescript issues in the docs. Spot checked a couple of the docs changes and verified that they rendered just fine in the docs.

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

lgtm, also spot checked the docs

@rspbot
Copy link

rspbot commented Mar 2, 2023

@rspbot
Copy link

rspbot commented Mar 2, 2023

## API Changes

unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }

@devongovett devongovett merged commit 9eb8796 into main Mar 2, 2023
@devongovett devongovett deleted the docs-ts branch March 2, 2023 22:24
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.

5 participants