Skip to content

Commit 72d007a

Browse files
type: React.Key => SafeKey (#578)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: afc163 <[email protected]>
1 parent 80d359d commit 72d007a

14 files changed

+123
-147
lines changed

.husky/pre-commit

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lint-staged

examples/form.tsx

+4-15
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const errorStyle = {
2121
};
2222

2323
class TreeSelectInput extends Component<{
24-
onChange?: Function;
24+
onChange?: (value: string[]) => void;
2525
style: React.CSSProperties;
2626
}> {
2727
onChange = (value, ...args) => {
@@ -105,11 +105,7 @@ const Demo = () => {
105105
>
106106
{(control, { errors }) => (
107107
<div>
108-
<TreeSelectInput
109-
{...tProps}
110-
{...control}
111-
style={{ width: 300 }}
112-
/>
108+
<TreeSelectInput {...tProps} {...control} style={{ width: 300 }} />
113109

114110
<p style={errorStyle}>{errors.join(',')}</p>
115111
</div>
@@ -122,18 +118,11 @@ const Demo = () => {
122118
<div>
123119
<Field
124120
name="select"
125-
rules={[
126-
{ required: true, type: 'array', message: 'select 需要必填' },
127-
]}
121+
rules={[{ required: true, type: 'array', message: 'select 需要必填' }]}
128122
>
129123
{(control, { errors }) => (
130124
<div>
131-
<Select
132-
style={{ width: 200 }}
133-
{...control}
134-
allowClear
135-
mode="multiple"
136-
>
125+
<Select style={{ width: 200 }} {...control} allowClear mode="multiple">
137126
<Option value="jack">jack</Option>
138127
<Option value="lucy">lucy</Option>
139128
<Option value="disabled" disabled>

package.json

+22-17
Original file line numberDiff line numberDiff line change
@@ -34,49 +34,54 @@
3434
"compile": "father build",
3535
"lint": "eslint src/ examples/ --ext .tsx,.ts,.jsx,.js",
3636
"now-build": "npm run build",
37-
"prepare": "dumi setup",
37+
"prepare": "husky && dumi setup",
3838
"prepublishOnly": "npm run compile && np --yolo --no-publish --any-branch",
3939
"prettier": "prettier '{src,tests}/**/*.{ts,tsx}' 'tests/**/*.js' --write",
4040
"start": "dumi dev",
4141
"test": "rc-test"
4242
},
43+
"lint-staged": {
44+
"*": "prettier --write --ignore-unknown"
45+
},
4346
"dependencies": {
4447
"@babel/runtime": "^7.25.7",
4548
"classnames": "2.x",
46-
"rc-select": "~14.15.0",
47-
"rc-tree": "~5.9.0",
49+
"rc-select": "~14.15.2",
50+
"rc-tree": "~5.10.0",
4851
"rc-util": "^5.43.0"
4952
},
5053
"devDependencies": {
51-
"@rc-component/father-plugin": "^1.0.0",
52-
"@rc-component/trigger": "^1.5.0",
53-
"@testing-library/react": "^12.0.0",
54-
"@types/jest": "^29.5.12",
54+
"@rc-component/father-plugin": "^1.1.0",
55+
"@rc-component/trigger": "^1.18.3",
56+
"@testing-library/react": "^12.1.5",
57+
"@types/jest": "^29.5.13",
5558
"@types/node": "^22.7.5",
56-
"@types/react": "^16.8.19",
57-
"@types/react-dom": "^18.2.19",
58-
"@types/warning": "^3.0.0",
59+
"@types/react": "^18.3.11",
60+
"@types/react-dom": "^18.3.1",
61+
"@types/warning": "^3.0.3",
5962
"@umijs/fabric": "^4.0.1",
63+
"cheerio": "1.0.0-rc.12",
6064
"cross-env": "^7.0.3",
6165
"dumi": "^2.4.12",
6266
"enzyme": "^3.11.0",
6367
"enzyme-adapter-react-16": "^1.15.8",
6468
"enzyme-to-json": "^3.6.2",
65-
"eslint": "^8.56.0",
66-
"eslint-plugin-jest": "^27.6.0",
69+
"eslint": "^8.57.1",
70+
"eslint-plugin-jest": "^27.9.0",
6771
"eslint-plugin-unicorn": "^56.0.0",
6872
"father": "^4.5.0",
6973
"glob": "^11.0.0",
74+
"husky": "^9.1.6",
75+
"lint-staged": "^15.2.10",
7076
"np": "^10.0.7",
7177
"prettier": "^3.3.3",
7278
"rc-dialog": "^9.6.0",
7379
"rc-field-form": "^2.4.0",
74-
"rc-test": "^7.1.0",
80+
"rc-test": "^7.1.1",
7581
"rc-virtual-list": "^3.14.8",
76-
"react": "16.x",
77-
"react-dom": "16.x",
78-
"typescript": "^5.6.3",
79-
"cheerio": "1.0.0-rc.12"
82+
"react": "^16.0.0",
83+
"react-dom": "^16.0.0",
84+
"typescript": "^5.6.3"
8085
},
8186
"peerDependencies": {
8287
"react": "*",

src/LegacyContext.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import * as React from 'react';
22
import type { DataEntity, IconType } from 'rc-tree/lib/interface';
3-
import type { Key, LegacyDataNode, RawValueType } from './interface';
3+
import type { LegacyDataNode, SafeKey } from './interface';
44

55
interface LegacyContextProps {
66
checkable: boolean | React.ReactNode;
7-
checkedKeys: Key[];
8-
halfCheckedKeys: Key[];
9-
treeExpandedKeys: Key[];
10-
treeDefaultExpandedKeys: Key[];
11-
onTreeExpand: (keys: Key[]) => void;
7+
checkedKeys: SafeKey[];
8+
halfCheckedKeys: SafeKey[];
9+
treeExpandedKeys: SafeKey[];
10+
treeDefaultExpandedKeys: SafeKey[];
11+
onTreeExpand: (keys: SafeKey[]) => void;
1212
treeDefaultExpandAll: boolean;
1313
treeIcon: IconType;
1414
showTreeIcon: boolean;
1515
switcherIcon: IconType;
1616
treeLine: boolean;
1717
treeNodeFilterProp: string;
18-
treeLoadedKeys: Key[];
18+
treeLoadedKeys: SafeKey[];
1919
treeMotion: any;
2020
loadData: (treeNode: LegacyDataNode) => Promise<unknown>;
21-
onTreeLoad: (loadedKeys: Key[]) => void;
21+
onTreeLoad: (loadedKeys: SafeKey[]) => void;
2222

23-
keyEntities: Record<RawValueType, DataEntity<any>>;
23+
keyEntities: Record<SafeKey, DataEntity<any>>;
2424
}
2525

2626
const LegacySelectContext = React.createContext<LegacyContextProps>(null);

src/OptionList.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import useMemo from 'rc-util/lib/hooks/useMemo';
88
import * as React from 'react';
99
import LegacyContext from './LegacyContext';
1010
import TreeSelectContext from './TreeSelectContext';
11-
import type { Key, TreeDataNode } from './interface';
11+
import type { SafeKey, TreeDataNode } from './interface';
1212
import { getAllKeys, isCheckDisabled } from './utils/valueUtil';
1313

1414
const HIDDEN_STYLE = {
@@ -23,7 +23,7 @@ const HIDDEN_STYLE = {
2323
};
2424

2525
interface TreeEventInfo {
26-
node: { key: Key };
26+
node: { key: SafeKey };
2727
selected?: boolean;
2828
checked?: boolean;
2929
}
@@ -77,7 +77,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
7777
);
7878

7979
// ========================== Active ==========================
80-
const [activeKey, setActiveKey] = React.useState<Key>(null);
80+
const [activeKey, setActiveKey] = React.useState<SafeKey>(null);
8181
const activeEntity = keyEntities[activeKey];
8282

8383
// ========================== Values ==========================
@@ -112,8 +112,8 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
112112
};
113113

114114
// =========================== Keys ===========================
115-
const [expandedKeys, setExpandedKeys] = React.useState<Key[]>(treeDefaultExpandedKeys);
116-
const [searchExpandedKeys, setSearchExpandedKeys] = React.useState<Key[]>(null);
115+
const [expandedKeys, setExpandedKeys] = React.useState<SafeKey[]>(treeDefaultExpandedKeys);
116+
const [searchExpandedKeys, setSearchExpandedKeys] = React.useState<SafeKey[]>(null);
117117

118118
const mergedExpandedKeys = React.useMemo(() => {
119119
if (treeExpandedKeys) {
@@ -129,7 +129,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
129129
// eslint-disable-next-line react-hooks/exhaustive-deps
130130
}, [searchValue]);
131131

132-
const onInternalExpand = (keys: Key[]) => {
132+
const onInternalExpand = (keys: SafeKey[]) => {
133133
setExpandedKeys(keys);
134134
setSearchExpandedKeys(keys);
135135

@@ -143,7 +143,7 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
143143
event.preventDefault();
144144
};
145145

146-
const onInternalSelect = (__: React.Key[], info: TreeEventInfo) => {
146+
const onInternalSelect = (__: SafeKey[], info: TreeEventInfo) => {
147147
const { node } = info;
148148

149149
if (checkable && isCheckDisabled(node)) {

src/TreeNode.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* istanbul ignore file */
22
import type * as React from 'react';
3-
import type { DataNode, Key } from './interface';
3+
import type { DataNode, SafeKey } from './interface';
44

55
export interface TreeNodeProps extends Omit<DataNode, 'children'> {
6-
value: Key;
6+
value: SafeKey;
77
children?: React.ReactNode;
88
}
99

0 commit comments

Comments
 (0)