Skip to content

Commit 67d602a

Browse files
committed
fix: update types
1 parent 8dd289c commit 67d602a

File tree

25 files changed

+57
-42
lines changed

25 files changed

+57
-42
lines changed

packages/core/src/helpers/assert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function isTangoVariable(name: string) {
3535
return /^tango\??\.(stores|services)\??\./.test(name) && name.split('.').length > 2;
3636
}
3737

38-
const templatePattern = /^{(.+)}$/s;
38+
const templatePattern = /^{(.+)}$/;
3939

4040
/**
4141
* 判断给定字符串是否被表达式容器`{expCode}`包裹

packages/core/src/helpers/object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function namesToImportDeclarations(
1111
names: string[],
1212
nameMap: Dict<IImportSpecifierSourceData>,
1313
) {
14-
const map = {};
14+
const map: Dict = {};
1515
names.forEach((name) => {
1616
const mod = nameMap[name];
1717
if (mod) {

packages/core/src/helpers/schema-helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { parseDndId, uuid } from '@music163/tango-helpers';
1+
import { Dict, parseDndId, uuid } from '@music163/tango-helpers';
22

33
// { id: 1, component, props: { id: 1 }, children: [ { id: 2, component } ] }
44
export function deepCloneNode(obj: any, component?: string): any {
55
function deepCloneObject() {
6-
const target = {};
6+
const target: Dict = {};
77
for (const key in obj) {
88
if (Object.hasOwn(obj, key)) {
99
target[key] = deepCloneNode(obj[key], component);

packages/designer/src/components/variable-tree/add-service.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { isValidFunctionCode, url2serviceName } from '@music163/tango-helpers';
1+
import { Dict, isValidFunctionCode, url2serviceName } from '@music163/tango-helpers';
22
import { InputCode } from '@music163/tango-ui';
33
import { Button, Dropdown, Form, FormProps, Input, Select, Space } from 'antd';
44
import { Box } from 'coral-system';
55
import React, { useState } from 'react';
66

77
interface AddServiceFormProps extends FormProps {
8-
initialValues?: object;
8+
initialValues?: Dict;
99
onSubmit: (values: object) => void;
1010
onCancel: () => void;
1111
serviceModules: object[];

packages/designer/src/dnd/hotkey.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { Dict } from '@music163/tango-helpers';
2+
13
/**
24
* 快捷键
35
*/
46
export class Hotkey {
5-
private readonly hotkeyMap = {};
7+
private readonly hotkeyMap: Dict = {};
68

79
constructor(hotkeys: Record<string, Function>) {
810
Object.keys(hotkeys).forEach((hotkey) => {

packages/designer/src/sandbox/sandbox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useImperativeHandle, ForwardedRef, useRef, useState, useEffect } from 'react';
22
import { Box } from 'coral-system';
33
import { CodeSandbox, CodeSandboxProps } from '@music163/tango-sandbox';
4-
import { getValue, isFunction, logger, pick, setValue } from '@music163/tango-helpers';
4+
import { Dict, getValue, isFunction, logger, pick, setValue } from '@music163/tango-helpers';
55
import { observer, useWorkspace, useDesigner } from '@music163/tango-context';
66
import { Simulator, Viewport } from '../simulator';
77
import { useSandboxQuery } from '../context';
@@ -88,7 +88,7 @@ function useSandbox({
8888
onViewChange: (data) => onViewChange && onViewChange(data, getSandboxConfig()),
8989
});
9090

91-
let files = Array.from(workspace.files.keys()).reduce((prev, filename) => {
91+
let files = Array.from(workspace.files.keys()).reduce<Dict>((prev, filename) => {
9292
let code = workspace.getFile(filename).code;
9393
if (filename === '/tango.config.json') {
9494
code = mergeTangoConfigJson(code, { isPreview, injectScript, formatter: configFormatter });

packages/designer/src/setters/event-setter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AutoComplete } from 'antd';
44
import { ActionSelect } from '@music163/tango-ui';
55
import { FormItemComponentProps } from '@music163/tango-setting-form';
66
import { useWorkspace, useWorkspaceData } from '@music163/tango-context';
7-
import { wrapCode } from '@music163/tango-helpers';
7+
import { Dict, wrapCode } from '@music163/tango-helpers';
88
import { ExpressionPopover } from './expression-setter';
99
import { value2code } from '@music163/tango-core';
1010

@@ -141,7 +141,7 @@ export function EventSetter(props: EventSetterProps) {
141141
);
142142
}
143143

144-
const handlerMap = {
144+
const handlerMap: Dict = {
145145
[EventAction.OpenModal]: 'openModal',
146146
[EventAction.CloseModal]: 'closeModal',
147147
[EventAction.NavigateTo]: 'navigateTo',

packages/designer/src/setters/expression-setter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export function ExpressionPopover({
182182
}));
183183

184184
const sandbox = useSandboxQuery();
185-
const evaluateContext = sandbox.window;
185+
const evaluateContext: any = sandbox.window;
186186

187187
const handleExpInputChange = (val: string) => {
188188
setExp(val?.trim());
@@ -253,7 +253,7 @@ export function ExpressionPopover({
253253
height="100%"
254254
showViewButton
255255
dataSource={dataSource || expressionVariables}
256-
appContext={sandbox?.window['tango']}
256+
appContext={evaluateContext['tango']}
257257
getStoreNames={() => Object.keys(workspace.storeModules)}
258258
serviceModules={serviceModules}
259259
getServiceData={(serviceKey) => {

packages/designer/src/setters/list-setter.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { css, Box } from 'coral-system';
33
import { Form, Input, Button, Popover } from 'antd';
44
import { DeleteOutlined, EditOutlined, HolderOutlined } from '@ant-design/icons';
55
import { FormItemComponentProps } from '@music163/tango-setting-form';
6+
import { Dict } from '@music163/tango-helpers';
67
import { DragBox } from '../components';
78

8-
function copyWithoutUndefined(source: Record<string, any>) {
9-
const ret = {};
9+
function copyWithoutUndefined(source: Dict) {
10+
const ret: Dict = {};
1011
for (const key in source) {
1112
if (source[key] !== undefined) {
1213
ret[key] = source[key];

packages/designer/src/setters/model-setter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function ModelSetter({
6060
}: FormItemComponentProps) {
6161
const [inputValue, setInputValue] = useState(value);
6262
const { modelVariables } = useWorkspaceData();
63-
const evaluateContext = useSandboxQuery().window || {};
63+
const evaluateContext: any = useSandboxQuery().window || {};
6464
const workspace = useWorkspace();
6565
const definedVariables = useMemo(() => {
6666
const list: string[] = [];

packages/designer/src/setters/render-setter.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
22
import { ActionSelect, InputCode } from '@music163/tango-ui';
33
import { FormItemComponentProps } from '@music163/tango-setting-form';
44
import { Box } from 'coral-system';
5+
import { Dict } from '@music163/tango-helpers';
56

67
interface IRenderOption {
78
label: string;
@@ -37,7 +38,7 @@ export function RenderSetter({
3738
}, [value]);
3839

3940
const optionsMap = useMemo(() => {
40-
return options.reduce((prev, cur) => {
41+
return options.reduce<Dict>((prev, cur) => {
4142
prev[cur.value] = cur;
4243
return prev;
4344
}, {});

packages/designer/src/setters/router-setter.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import React, { useEffect, useState } from 'react';
22
import { Box } from 'coral-system';
33
import { Input, Radio } from 'antd';
4-
import { isValidUrl } from '@music163/tango-helpers';
4+
import { Dict, isValidUrl } from '@music163/tango-helpers';
55
import { FormItemComponentProps } from '@music163/tango-setting-form';
66
import { useWorkspaceData } from '@music163/tango-context';
77
import { PickerSetter } from './picker-setter';
88

9+
const routerModeMap: Dict = {
10+
link: '链接',
11+
router: '路由',
12+
both: '',
13+
};
14+
915
export function RouterSetter(props: FormItemComponentProps) {
1016
const [type, setType] = useState<'input' | 'select'>(() => {
1117
return isValidUrl(props.value) ? 'input' : 'select';
@@ -37,7 +43,7 @@ export function RouterSetter(props: FormItemComponentProps) {
3743
)}
3844
{type === 'input' && (
3945
<Input
40-
placeholder={`请输入任意${{ link: '链接', router: '路由', both: '' }[displayType]}地址`}
46+
placeholder={`请输入任意${routerModeMap[displayType]}地址`}
4147
{...props}
4248
value={input}
4349
onChange={(e) => setInput(e.target.value)}

packages/designer/src/setting-panel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { Box } from 'coral-system';
33
import { SettingForm, FormModel, SettingFormProps } from '@music163/tango-setting-form';
44
import { Panel } from '@music163/tango-ui';
5-
import { clone, parseDndId } from '@music163/tango-helpers';
5+
import { clone, Dict, parseDndId } from '@music163/tango-helpers';
66
import { observer, useDesigner, useWorkspace } from '@music163/tango-context';
77
import { registerBuiltinSetters } from './setters';
88

@@ -34,7 +34,7 @@ export const SettingPanel = observer((props: SettingPanelProps) => {
3434
}
3535

3636
const getSettingValue = (attributes: Record<string, string>) => {
37-
const ret = {};
37+
const ret: Dict = {};
3838
const keys = Object.keys(attributes);
3939
for (const key of keys) {
4040
if (/^data-/.test(key)) {

packages/designer/src/sidebar/components-panel.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useMemo, useState } from 'react';
22
import { Box, Grid, Text } from 'coral-system';
33
import styled, { css } from 'styled-components';
44
import {
5+
Dict,
56
IComponentPrototype,
67
MenuDataType,
78
MenuValueType,
@@ -66,7 +67,7 @@ export interface ComponentsPanelProps {
6667
layout?: 'grid' | 'line';
6768
}
6869

69-
const localeMap = {
70+
const localeMap: Dict = {
7071
common: '基础组件',
7172
atom: '原子组件',
7273
snippet: '组合',
@@ -124,7 +125,7 @@ export const ComponentsPanel = observer(
124125
const tabs = Object.keys(menuData).map((key) => ({
125126
key,
126127
label: localeMap[key],
127-
children: <MaterialList data={menuData[key]} />,
128+
children: <MaterialList data={(menuData as any)[key]} />,
128129
}));
129130

130131
if (showBizComps) {

packages/designer/src/sidebar/datasource-panel/interface-config.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const DataSourceView = observer(() => {
2424
<Box className="ServiceFunctionList" p="m">
2525
<VariableTree
2626
dataSource={serviceVariables}
27-
appContext={sandbox?.window['tango']}
27+
appContext={(sandbox?.window as any)['tango']}
2828
serviceModules={serviceModules}
2929
onRemoveService={(variableKey) => {
3030
workspace.removeServiceFunction(variableKey);

packages/designer/src/sidebar/datasource-panel/proxy-config.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ConfigGroup, ConfigItem } from '@music163/tango-ui';
44
import { Box, css } from 'coral-system';
55
import { Input, Switch, Form, Button, message, FormProps } from 'antd';
66
import { CloseCircleOutlined, CloseOutlined } from '@ant-design/icons';
7+
import { Dict } from '@music163/tango-helpers';
78

89
export default observer(() => {
910
const workspace = useWorkspace();
@@ -63,7 +64,7 @@ function ProxyManage({
6364
initialValues: initialValuesProp = {},
6465
onSave,
6566
}: {
66-
initialValues?: object;
67+
initialValues?: Dict;
6768
onSave?: (values: any) => void;
6869
}) {
6970
const initialValues = useMemo(() => {
@@ -84,7 +85,7 @@ function ProxyManage({
8485
{...proxyManageFormStyle}
8586
initialValues={initialValues}
8687
onFinish={(values) => {
87-
const proxy = values.proxy.reduce((prev: object, { path, ...rest }: any) => {
88+
const proxy = values.proxy.reduce((prev: any, { path, ...rest }: any) => {
8889
prev[path] = rest;
8990
return prev;
9091
}, {});

packages/designer/src/sidebar/outline-panel/state-tree.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React, { useEffect, useReducer } from 'react';
22
import { observer } from '@music163/tango-context';
3-
import { isFunction, isObject, pick } from '@music163/tango-helpers';
3+
import { Dict, isFunction, isObject, pick } from '@music163/tango-helpers';
44
import { CollapsePanel, IconButton, JsonView } from '@music163/tango-ui';
55
import { ReloadOutlined } from '@ant-design/icons';
66
import { useSandboxQuery } from '../../context';
77

8-
function processTango(obj: any = {}, index = 0) {
9-
const ret = {};
8+
function processTango(obj: Dict = {}, index = 0) {
9+
const ret: Dict = {};
1010
Object.keys(obj).forEach((key) => {
1111
const val = obj[key];
1212
if (index > 2) {
@@ -25,7 +25,7 @@ function processTango(obj: any = {}, index = 0) {
2525
export const StateTree = observer(() => {
2626
const sandboxQuery = useSandboxQuery();
2727
const [, forceUpdate] = useReducer((x) => x + 1, 0);
28-
const tangoContext = pick(sandboxQuery.window['tango'] || {}, [
28+
const tangoContext = pick((sandboxQuery.window as any)['tango'] || {}, [
2929
'stores',
3030
'pageStore',
3131
'services',

packages/designer/src/sidebar/resizable-box.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const resizeHandleStyle = (axis: ResizableBoxProps['axis'], barStyle: HTMLCoralP
1919
cursor: ${axis === 'x' ? 'col-resize' : 'row-resize'};
2020
${barStyle &&
2121
Object.keys(barStyle)
22-
.map((key) => `${key}: ${barStyle[key]};`)
22+
.map((key) => `${key}: ${(barStyle as any)[key]};`)
2323
.join('')}
2424
&:hover,
2525
&:active {

packages/helpers/src/helpers/array.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function filterTreeData<T = unknown>(
4343
childrenProp = 'children',
4444
onlyLeaf = false,
4545
) {
46-
const reducer = (result: T[], current: T) => {
46+
const reducer = (result: T[], current: any) => {
4747
if (current[childrenProp]) {
4848
const newChildren = current[childrenProp].reduce(reducer, []);
4949
if (newChildren.length) {
@@ -70,7 +70,7 @@ export function mapTreeData<T = unknown>(
7070
mapper: (node: T) => any,
7171
childrenProp = 'children',
7272
) {
73-
return treeData.map((node) => {
73+
return treeData.map((node: any) => {
7474
const newNode = mapper(node);
7575
if (node[childrenProp]) {
7676
newNode[childrenProp] = mapTreeData(node[childrenProp], mapper, childrenProp);

packages/helpers/src/helpers/code-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function isValidFunctionCode(str: string) {
3232
}
3333
}
3434

35-
const templatePattern = /^{{(.+)}}$/s;
35+
const templatePattern = /^{{(.+)}}$/;
3636

3737
/**
3838
* 判断给定代码是否被双花括号包裹

packages/helpers/src/helpers/object.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import get from 'lodash.get';
22
import set from 'lodash.set';
3+
import { Dict } from '../types';
34

45
/**
56
* 合并 target 和 source 对象,source 对象的优先级更高,如存在重名,覆盖 target 中的 key
@@ -45,7 +46,7 @@ export function clone(obj: any, withUndefined = true) {
4546
return obj;
4647
}
4748

48-
const target = {};
49+
const target: Dict = {};
4950
for (const key in obj) {
5051
if (withUndefined) {
5152
target[key] = obj[key];
@@ -65,7 +66,7 @@ export function omit(obj: any, keys: string[]) {
6566
}
6667

6768
export function pick(obj: any, keys: string[]) {
68-
const target = {};
69+
const target: Dict = {};
6970
for (const key of keys) {
7071
target[key] = obj[key];
7172
}

packages/helpers/src/hoc/with-dnd.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function withDnd(options: IWithDndOptions<any>) {
5757
const override = options.overrideProps || {};
5858
const renderFooter = options.renderFooter || renderEmpty;
5959

60-
const Component = forwardRef<unknown, P & DraggableComponentProps>((props, refProp) => {
60+
const Component = forwardRef<unknown, P & DraggableComponentProps>((props: any, refProp) => {
6161
const dndProps = {
6262
[SLOT.id]: props.tid, // id 作为唯一标记
6363
[SLOT.dnd]: props[SLOT.dnd], // dnd 作为追踪标记

packages/helpers/src/stores/list-store.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { warning } from '../helpers';
2+
import { Dict } from '../types';
23

3-
type ListStoreOptionsType<T = object> = {
4+
type ListStoreOptionsType<T extends Dict = Dict> = {
45
data: T[];
56
keyProp?: string;
67
labelProp?: string;
78
childrenProp?: string;
89
};
910

10-
export class ListStore<T = object> {
11+
export class ListStore<T extends Dict = Dict> {
1112
private nodeMap: Map<string, T>;
1213
private keyProp: string;
1314
private childrenProp: string;

packages/setting-form/src/form.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
noop,
88
filterTreeData,
99
mapTreeData,
10+
Dict,
1011
} from '@music163/tango-helpers';
1112
import { Action, Search, Tabs } from '@music163/tango-ui';
1213
import { SettingFormItem, register } from './form-item';
@@ -24,7 +25,7 @@ function normalizeComponentProps(
2425
props: IComponentPrototype['props'],
2526
groupOptions: IFormTabsGroupOption[],
2627
) {
27-
const groups: Record<string, IComponentProp[]> = groupOptions.reduce((prev, cur) => {
28+
const groups: Record<string, IComponentProp[]> = groupOptions.reduce<Dict>((prev, cur) => {
2829
prev[cur.value] = [];
2930
return prev;
3031
}, {});

0 commit comments

Comments
 (0)