Skip to content
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

Update react types #5237

Merged
merged 19 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module.exports = {
}, {
files: ['**/test/**', '**/stories/**', '**/docs/**', '**/chromatic/**', '**/__tests__/**'],
rules: {
'rsp-rules/no-react-key': [ERROR],
'rsp-rules/act-events-test': ERROR,
'rsp-rules/no-getByRole-toThrow': ERROR,
'rulesdir/imports': OFF,
Expand Down Expand Up @@ -182,7 +183,8 @@ module.exports = {
'react-hooks/exhaustive-deps': WARN,

// custom rules
'rulesdir/sort-imports': [ERROR],
'rsp-rules/no-react-key': [ERROR],
'rsp-rules/sort-imports': [ERROR],
'rulesdir/imports': [ERROR],
'rulesdir/useLayoutEffectRule': [ERROR],
'rulesdir/pure-render': [ERROR],
Expand Down
2 changes: 1 addition & 1 deletion examples/rsp-cra-18/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function App() {
{(item: any) =>
(<Row key={item.foo} UNSTABLE_childItems={item.childRows}>
{(key) => {
return <Cell>{item[key.toString()]}</Cell>;
return <Cell>{item[key]}</Cell>;
Copy link
Member Author

Choose a reason for hiding this comment

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

}}
</Row>)
}
Expand Down
8 changes: 4 additions & 4 deletions examples/rsp-cra-18/src/Journal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Key} from 'react'
import {Key} from '@react-types/shared';

interface Journal{
rate: Key,
description: string,
rate: Key,
description: string,
id: number
}

export default Journal
export default Journal
2 changes: 1 addition & 1 deletion examples/rsp-cra-18/src/JournalEntries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function JournalEntries(props : {list : Journal[]}){
const element = props.list.map(item => (
<li key={item.id}>
<Divider size="M" marginTop="size-200" marginBottom="size-300" />
<p>Your day was: {item.rate.toString()} </p>
<p>Your day was: {item.rate} </p>
<p>{item.description}</p>
</li>

Expand Down
2 changes: 1 addition & 1 deletion examples/rsp-next-ts-17/components/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react";

interface SectionProps {
title: string;
children: JSX.Element | JSX.Element[];
children: React.JSX.Element | React.JSX.Element[];
Copy link
Member Author

Choose a reason for hiding this comment

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

React got rid of the global namespace, but JSX is still in the React namespace, so reference through that
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L3309

Copy link
Member

Choose a reason for hiding this comment

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

deprecated but not removed. Doesn't really explain why it broke. Any idea?

Copy link
Member Author

@snowystinger snowystinger Oct 14, 2023

Choose a reason for hiding this comment

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

It broke between RAC alpha 4 and alpha 5 https://unpkg.com/browse/react-aria-components@1.0.0-alpha.5/dist/
Here's the list of commits between those two versions 5911ed2...7186d21

in alpha 4, we exported using the global namespace which included JSX. in alpha 5, we stopped doing that and started exporting the React namespaced version.

I suspect some parcel or update to types in our own repo which caused us to stop using the global namespace, but I haven't nailed it down yet. Upgrading the types caused it to be marked as deprecated in our own code base, but the problem was already present.

I'm following up with the issue author because I suspect they have multiple copies of react types. I suspect users just need to upgrade their types and dedupe.

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 "broke" in 1123b0f
we upgraded our react/types from 17 to 18, and it seems as though our type generation is smart enough to find the non-global namespace of JSX and prefer that. I'm not sure where that is in the parcel transformer?

I haven't actually "fixed" it in this PR, I think people have to update themselves which is what I followed up with the issue author to do.

In addition to explicit references to the global JSX (RAC DialogTrigger), we also have many implicit references to it. Any inferred component's return value for instance. So if we wanted to "fix" this by using the global JSX namespace again, we'd need to handle both of these.

}

export default function Section(props: SectionProps) {
Expand Down
2 changes: 1 addition & 1 deletion examples/rsp-next-ts/components/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react";

interface SectionProps {
title: string;
children: JSX.Element | JSX.Element[];
children: React.JSX.Element | React.JSX.Element[];
}

export default function Section(props: SectionProps) {
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"copyrights": "babel-node --presets @babel/env ./scripts/addHeaders.js",
"build:icons": "babel-node --presets @babel/env ./scripts/buildIcons.js",
"clean:icons": "babel-node --presets @babel/env ./scripts/cleanIcons.js",
"postinstall": "yarn build:icons && patch-package",
"postinstall": "patch-package && yarn build:icons",
Copy link
Member Author

Choose a reason for hiding this comment

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

run first so that we can fix lodash types before icons build since they'll fail if the types are bad

"plop": "plop --plopfile scripts/plopfile.js",
"chromatic": "NODE_ENV=production CHROMATIC=1 chromatic --project-token $CHROMATIC_PROJECT_TOKEN --build-script-name 'build:chromatic'",
"chromatic:forced-colors": "NODE_ENV=production CHROMATIC=1 chromatic --project-token $CHROMATIC_FC_PROJECT_TOKEN --build-script-name 'build:chromatic-fc'",
Expand Down Expand Up @@ -98,10 +98,10 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/react": "^18.2.7",
"@types/react": "^18.2.28",
"@types/storybook__react": "^5.2.1",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
"@typescript-eslint/eslint-plugin": "^6.7.5",
"@typescript-eslint/parser": "^6.7.5",
"autoprefixer": "^9.6.0",
"axe-core": "^4.6.3",
"axe-playwright": "^1.1.11",
Expand Down Expand Up @@ -169,7 +169,7 @@
"tailwindcss": "^3.2.2",
"tailwindcss-animate": "^1.0.7",
"tempy": "^0.5.0",
"typescript": "5.0.4",
"typescript": "5.2.2",
"typescript-strict-plugin": "^2.0.0",
"verdaccio": "^5.13.0",
"walk-object": "^4.0.0",
Expand All @@ -178,6 +178,7 @@
},
"resolutions": {
"@babel/core": "7.12.10",
"@types/react": "18.2.28",
"postcss": "8.4.24",
"postcss-custom-properties": "13.2.0",
"postcss-import": "15.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/actiongroup/src/useActionGroupItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
* governing permissions and limitations under the License.
*/

import {DOMAttributes, FocusableElement} from '@react-types/shared';
import {Key, RefObject, useEffect} from 'react';
import {DOMAttributes, FocusableElement, Key} from '@react-types/shared';
import {ListState} from '@react-stately/list';
import {mergeProps, useEffectEvent} from '@react-aria/utils';
import {PressProps} from '@react-aria/interactions';
import {RefObject, useEffect} from 'react';

export interface AriaActionGroupItemProps {
key: Key
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/dnd/src/DragPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import {flushSync} from 'react-dom';
import React, {RefObject, useImperativeHandle, useRef, useState} from 'react';

export interface DragPreviewProps {
children: (items: DragItem[]) => JSX.Element
children: (items: DragItem[]) => React.JSX.Element
}

function DragPreview(props: DragPreviewProps, ref: RefObject<DragPreviewRenderer>) {
let render = props.children;
let [children, setChildren] = useState<JSX.Element>(null);
let [children, setChildren] = useState<React.JSX.Element>(null);
let domRef = useRef(null);

useImperativeHandle(ref, () => (items: DragItem[], callback: (node: HTMLElement) => void) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-aria/dnd/src/useDraggableItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import {AriaButtonProps} from '@react-types/button';
import {clearGlobalDnDState, isInternalDropOperation, setDraggingKeys, useDragModality} from './utils';
import {DraggableCollectionState} from '@react-stately/dnd';
import {HTMLAttributes, Key} from 'react';
import {HTMLAttributes} from 'react';
// @ts-ignore
import intlMessages from '../intl/*.json';
import {Key} from '@react-types/shared';
import {useDescription} from '@react-aria/utils';
import {useDrag} from './useDrag';
import {useLocalizedStringFormatter} from '@react-aria/i18n';
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/dnd/src/useDropIndicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

import * as DragManager from './DragManager';
import {DroppableCollectionState} from '@react-stately/dnd';
import {DropTarget} from '@react-types/shared';
import {DropTarget, Key} from '@react-types/shared';
import {getDroppableCollectionId} from './utils';
import {HTMLAttributes, Key, RefObject} from 'react';
import {HTMLAttributes, RefObject} from 'react';
// @ts-ignore
import intlMessages from '../intl/*.json';
import {useDroppableItem} from './useDroppableItem';
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-aria/dnd/src/useDroppableCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ import {
DropPosition,
DropTarget,
DropTargetDelegate,
Key,
KeyboardDelegate,
Node
} from '@react-types/shared';
import * as DragManager from './DragManager';
import {DroppableCollectionState} from '@react-stately/dnd';
import {HTMLAttributes, Key, RefObject, useCallback, useEffect, useRef} from 'react';
import {HTMLAttributes, RefObject, useCallback, useEffect, useRef} from 'react';
import {mergeProps, useId, useLayoutEffect} from '@react-aria/utils';
import {setInteractionModality} from '@react-aria/interactions';
import {useAutoScroll} from './useAutoScroll';
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/dnd/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
*/

import {CUSTOM_DRAG_TYPE, DROP_OPERATION, GENERIC_TYPE, NATIVE_DRAG_TYPES} from './constants';
import {DirectoryDropItem, DragItem, DropItem, FileDropItem, DragTypes as IDragTypes, TextDropItem} from '@react-types/shared';
import {DirectoryDropItem, DragItem, DropItem, FileDropItem, DragTypes as IDragTypes, Key, TextDropItem} from '@react-types/shared';
import {DroppableCollectionState} from '@react-stately/dnd';
import {getInteractionModality, useInteractionModality} from '@react-aria/interactions';
import {Key, RefObject} from 'react';
import {RefObject} from 'react';

interface DroppableCollectionMap {
id: string,
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/dnd/stories/Reorderable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {FocusRing} from '@react-aria/focus';
import Folder from '@spectrum-icons/workflow/Folder';
import {GridCollection, useGridState} from '@react-stately/grid';
import {Item} from '@react-stately/collections';
import {ItemDropTarget} from '@react-types/shared';
import {ItemDropTarget, Key} from '@react-types/shared';
import {ListDropTargetDelegate} from '@react-aria/dnd';
import {ListKeyboardDelegate} from '@react-aria/selection';
import React, {useRef} from 'react';
Expand All @@ -45,7 +45,7 @@ export function ReorderableGridExample(props) {
]
});

let onMove = (keys: React.Key[], target: ItemDropTarget) => {
let onMove = (keys: Key[], target: ItemDropTarget) => {
if (target.dropPosition === 'before') {
list.moveBefore(target.key, keys);
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/grid/src/GridKeyboardDelegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
* governing permissions and limitations under the License.
*/

import {Direction, KeyboardDelegate, Node} from '@react-types/shared';
import {Direction, Key, KeyboardDelegate, Node} from '@react-types/shared';
import {getChildNodes, getFirstItem, getLastItem, getNthItem} from '@react-stately/collections';
import {GridCollection} from '@react-types/grid';
import {Key, RefObject} from 'react';
import {Layout, Rect} from '@react-stately/virtualizer';
import {RefObject} from 'react';

export interface GridKeyboardDelegateOptions<T, C> {
collection: C,
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/grid/src/useGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
* governing permissions and limitations under the License.
*/

import {AriaLabelingProps, DOMAttributes, DOMProps, KeyboardDelegate} from '@react-types/shared';
import {AriaLabelingProps, DOMAttributes, DOMProps, Key, KeyboardDelegate} from '@react-types/shared';
import {filterDOMProps, mergeProps, useId} from '@react-aria/utils';
import {GridCollection} from '@react-types/grid';
import {GridKeyboardDelegate} from './GridKeyboardDelegate';
import {gridMap} from './utils';
import {GridState} from '@react-stately/grid';
import {Key, RefObject, useCallback, useMemo} from 'react';
import {RefObject, useCallback, useMemo} from 'react';
import {useCollator, useLocale} from '@react-aria/i18n';
import {useGridSelectionAnnouncement} from './useGridSelectionAnnouncement';
import {useHasTabbableChild} from '@react-aria/focus';
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/grid/src/useGridSelectionAnnouncement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
*/

import {announce} from '@react-aria/live-announcer';
import {Collection, Node, Selection} from '@react-types/shared';
import {Collection, Key, Node, Selection} from '@react-types/shared';
// @ts-ignore
import intlMessages from '../intl/*.json';
import {Key, useRef} from 'react';
import {SelectionManager} from '@react-stately/selection';
import {useLocalizedStringFormatter} from '@react-aria/i18n';
import {useRef} from 'react';
import {useUpdateEffect} from '@react-aria/utils';

export interface GridSelectionAnnouncementProps {
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-aria/grid/src/useGridSelectionCheckbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {GridCollection} from '@react-types/grid';
import {GridState} from '@react-stately/grid';
// @ts-ignore
import intlMessages from '../intl/*.json';
import {Key} from 'react';
import {Key} from '@react-types/shared';
import {useId} from '@react-aria/utils';
import {useLocalizedStringFormatter} from '@react-aria/i18n';

Expand Down
3 changes: 1 addition & 2 deletions packages/@react-aria/grid/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

import type {GridCollection} from '@react-types/grid';
import type {GridState} from '@react-stately/grid';
import {Key} from 'react';
import type {KeyboardDelegate} from '@react-types/shared';
import type {Key, KeyboardDelegate} from '@react-types/shared';

interface GridMapShared {
keyboardDelegate: KeyboardDelegate,
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-aria/gridlist/src/useGridList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import {
DisabledBehavior,
DOMAttributes,
DOMProps,
Key,
KeyboardDelegate,
MultipleSelection
} from '@react-types/shared';
import {filterDOMProps, mergeProps, useId} from '@react-aria/utils';
import {Key, RefObject} from 'react';
import {listMap} from './utils';
import {ListState} from '@react-stately/list';
import {RefObject} from 'react';
import {useGridSelectionAnnouncement, useHighlightSelectionDescription} from '@react-aria/grid';
import {useHasTabbableChild} from '@react-aria/focus';
import {useSelectableList} from '@react-aria/selection';
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-aria/gridlist/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* governing permissions and limitations under the License.
*/

import {Key} from 'react';
import {Key} from '@react-types/shared';
import type {ListState} from '@react-stately/list';

interface ListMapShared {
Expand Down
4 changes: 0 additions & 4 deletions packages/@react-aria/i18n/src/useListFormatter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ import {useMemo} from 'react';
* and handles caching of the list formatter for performance.
* @param options - Formatting options.
*/

// Typescript version 4.7 supports Intl.ListFormat - TODO upgrade
// @ts-ignore
export function useListFormatter(options: Intl.ListFormatOptions = {}): Intl.ListFormat {
let {locale} = useLocale();
// @ts-ignore
return useMemo(() => new Intl.ListFormat(locale, options), [locale, options]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import {Cell, Column, Row, TableBody, TableHeader, TableView} from '@react-spectrum/table';
import {Key} from '@react-types/shared';
import React, {useState} from 'react';
import {SearchField} from '@react-spectrum/searchfield';

Expand Down Expand Up @@ -72,7 +73,7 @@ function SearchExample() {
<TableBody items={items}>
{item =>
(<Row key={item.foo}>
{key => <Cell>{item[key]}</Cell>}
{(key: Key) => <Cell>{item[key]}</Cell>}
</Row>)
}
</TableBody>
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/listbox/src/useOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
* governing permissions and limitations under the License.
*/

import {DOMAttributes, FocusableElement} from '@react-types/shared';
import {DOMAttributes, FocusableElement, Key} from '@react-types/shared';
import {filterDOMProps, isMac, isWebKit, mergeProps, useSlotId} from '@react-aria/utils';
import {getItemCount} from '@react-stately/collections';
import {getItemId, listData} from './utils';
import {isFocusVisible, useHover} from '@react-aria/interactions';
import {Key, RefObject} from 'react';
import {ListState} from '@react-stately/list';
import {RefObject} from 'react';
import {SelectableItemStates, useSelectableItem} from '@react-aria/selection';

export interface OptionAria extends SelectableItemStates {
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-aria/listbox/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* governing permissions and limitations under the License.
*/

import {Key} from 'react';
import {Key} from '@react-types/shared';
import {ListState} from '@react-stately/list';

interface ListData {
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/menu/src/useMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
*/

import {AriaMenuProps} from '@react-types/menu';
import {DOMAttributes, KeyboardDelegate} from '@react-types/shared';
import {DOMAttributes, Key, KeyboardDelegate} from '@react-types/shared';
import {filterDOMProps, mergeProps} from '@react-aria/utils';
import {Key, RefObject} from 'react';
import {RefObject} from 'react';
import {TreeState} from '@react-stately/tree';
import {useSelectableList} from '@react-aria/selection';

Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/menu/src/useMenuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
* governing permissions and limitations under the License.
*/

import {DOMAttributes, FocusableElement, PressEvent} from '@react-types/shared';
import {DOMAttributes, FocusableElement, Key, PressEvent} from '@react-types/shared';
import {filterDOMProps, mergeProps, useEffectEvent, useLayoutEffect, useRouter, useSlotId} from '@react-aria/utils';
import {focusSafely} from '@react-aria/focus';
import {getItemCount} from '@react-stately/collections';
import {isFocusVisible, useHover, useKeyboard, usePress} from '@react-aria/interactions';
import {Key, RefObject, useCallback, useRef} from 'react';
import {menuData} from './useMenu';
import {RefObject, useCallback, useRef} from 'react';
import {TreeState} from '@react-stately/tree';
import {useLocale} from '@react-aria/i18n';
import {useSelectableItem} from '@react-aria/selection';
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/selection/src/ListKeyboardDelegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
* governing permissions and limitations under the License.
*/

import {Collection, Direction, KeyboardDelegate, Node, Orientation} from '@react-types/shared';
import {Collection, Direction, Key, KeyboardDelegate, Node, Orientation} from '@react-types/shared';
import {isScrollable} from '@react-aria/utils';
import {Key, RefObject} from 'react';
import {RefObject} from 'react';

interface ListKeyboardDelegateOptions<T> {
collection: Collection<Node<T>>,
Expand Down
Loading