Skip to content

Commit 68ceca3

Browse files
authored
fix(types): fix type errors and adjust type definitions (#3474)
- Fixed various type errors - Adjusted .d.ts type declaration files - Updated tsconfig.json configuration
1 parent f141aab commit 68ceca3

File tree

12 files changed

+1049
-961
lines changed

12 files changed

+1049
-961
lines changed

packages/web-vue/components/_components/virtual-list-v2/virtual-list.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ import {
5151
nextTick,
5252
ref,
5353
toRefs,
54-
watch,
55-
reactive,
54+
PropType,
5655
} from 'vue';
5756
import { useSize } from './hooks/use-size';
5857
import VirtualListItem from './virtual-list-item';
@@ -69,7 +68,7 @@ export default defineComponent({
6968
default: 200,
7069
},
7170
data: {
72-
type: Array,
71+
type: Array as PropType<Record<string, any>[]>,
7372
default: () => [],
7473
},
7574
threshold: {

packages/web-vue/components/anchor/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { InjectionKey } from 'vue';
33
export interface AnchorContext {
44
currentLink: string;
55
addLink: (hash: string, node: HTMLElement) => void;
6-
removeLink: () => void;
7-
handleClick: (e: Event, hash?: string) => void;
6+
removeLink: (hash: string) => void;
7+
handleClick: (e: MouseEvent, hash?: string) => void;
88
}
99

1010
export const anchorInjectionKey: InjectionKey<AnchorContext> =

packages/web-vue/components/breadcrumb/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { InjectionKey, Slots } from 'vue';
33
export interface BreadcrumbContext {
44
total: number;
55
maxCount: number;
6-
separator: string | number;
6+
separator?: string | number;
77
needHide: boolean;
88
slots: Slots;
99
}

packages/web-vue/components/button/button.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@click="handleClick"
1010
>
1111
<span v-if="loading || $slots.icon" :class="`${prefixCls}-icon`">
12-
<icon-loading v-if="loading" spin="true" />
12+
<icon-loading v-if="loading" spin />
1313
<slot v-else name="icon" />
1414
</span>
1515
<slot />
@@ -119,7 +119,7 @@ export default defineComponent({
119119
* @en Set the native `type` attribute of `button`, optional values refer to [HTML](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-type "_blank")
120120
*/
121121
htmlType: {
122-
type: String,
122+
type: String as PropType<HTMLButtonElement['type']>,
123123
default: 'button',
124124
},
125125
/**

packages/web-vue/components/calendar/header.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import { isArray } from '../_utils/is';
1010
import { getPrefixCls } from '../_utils/global-config';
1111
import { useI18n } from '../locale';
1212

13-
function getPopupContainer(node: HTMLElement): Element {
14-
return node.parentElement;
15-
}
16-
1713
export default defineComponent({
1814
name: 'Header',
1915
props: {
@@ -56,7 +52,7 @@ export default defineComponent({
5652
required: true,
5753
},
5854
onModeChange: {
59-
type: Function,
55+
type: Function as PropType<(value: any, ev: Event) => void>,
6056
required: true,
6157
},
6258
headerValueFormat: {
@@ -110,19 +106,19 @@ export default defineComponent({
110106
<Select
111107
size="small"
112108
class={`${prefixCls}-header-value-year`}
113-
value={pageShowDateYear}
109+
defaultValue={pageShowDateYear.value}
114110
options={optionsYear.value}
115111
onChange={props.onYearChange}
116-
getPopupContainer={getPopupContainer}
112+
popupContainer={`${prefixCls}-header`}
117113
/>
118114
{props.mode === 'month' && (
119115
<Select
120116
size="small"
121117
class={`${prefixCls}-header-value-month`}
122-
value={pageShowDateMonth}
118+
defaultValue={pageShowDateMonth.value}
123119
options={optionsMonth}
124120
onChange={props.onMonthChange}
125-
getPopupContainer={getPopupContainer}
121+
popupContainer={`${prefixCls}-header`}
126122
/>
127123
)}
128124
</>
@@ -131,7 +127,7 @@ export default defineComponent({
131127
<div
132128
class={`${prefixCls}-header-icon`}
133129
role="button"
134-
tabIndex={0}
130+
tabindex={0}
135131
onClick={() => props.changePageShowDate('prev', props.mode)}
136132
>
137133
<IconLeft />
@@ -146,7 +142,7 @@ export default defineComponent({
146142
</div>
147143
<div
148144
role="button"
149-
tabIndex={0}
145+
tabindex={0}
150146
class={`${prefixCls}-header-icon`}
151147
onClick={() => props.changePageShowDate('next', props.mode)}
152148
>

packages/web-vue/components/calendar/month.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function getAllDaysByTime(
5959
}
6060
const rows = Array(6)
6161
.fill(null)
62-
.map(() => []);
62+
.map(() => [] as any[]);
6363
for (let i = 0; i < 6; i++) {
6464
rows[i] = flatRows.slice(i * 7, 7 * (i + 1));
6565
if (isWeek) {
@@ -177,7 +177,7 @@ export default defineComponent({
177177
const selectedWeek =
178178
props.value &&
179179
col.weekRows.find(
180-
(r) => r.year === rowYear && r.month === rowMonth
180+
(r: any) => r.year === rowYear && r.month === rowMonth
181181
) &&
182182
rowWeek === col.weekOfYear;
183183
return (
@@ -238,7 +238,7 @@ export default defineComponent({
238238
},
239239
]}
240240
>
241-
{renderDays(row)}
241+
{renderDays(row as any[])}
242242
</div>
243243
))}
244244
</div>

packages/web-vue/components/calendar/year.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default defineComponent({
100100
<div class={`${prefixCls}-year`}>
101101
{mg.map((row, rowIndex) => (
102102
<div class={`${prefixCls}-year-row`} key={rowIndex}>
103-
{row.map((col) => {
103+
{row.map((col: any) => {
104104
const time = dayjs(
105105
`${showYear.value}-${padStart(col.value + 1, 2, '0')}-01`
106106
);

packages/web-vue/components/mention/mention.tsx

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ export default defineComponent({
271271
const nextValue = `${head}${match}${tail}`;
272272

273273
_value.value = nextValue;
274-
emit('select', value);
274+
emit(
275+
'select',
276+
value as string | number | Record<string, any> | undefined
277+
);
275278
emit('update:modelValue', nextValue);
276279
emit('change', nextValue);
277280
resetMeasureInfo();
@@ -384,27 +387,28 @@ export default defineComponent({
384387
onKeydown={handleKeyDown}
385388
/>
386389
</ResizeObserver>
387-
{measureInfo.value.measuring && validOptionInfos.value.length > 0 && (
388-
<div
389-
ref={mirrorRef}
390-
style={mirrorStyle.value}
391-
class={`${prefixCls}-measure`}
392-
>
393-
{computedValue.value?.slice(0, measureInfo.value.location)}
394-
<Trigger
395-
v-slots={{ content: renderDropdown }}
396-
trigger="focus"
397-
position="bl"
398-
popupOffset={4}
399-
preventFocus={true}
400-
popupVisible={computedPopupVisible.value}
401-
clickToClose={false}
402-
onPopupVisibleChange={handlePopupVisibleChange}
390+
{measureInfo.value.measuring &&
391+
validOptionInfos.value.length > 0 && (
392+
<div
393+
ref={mirrorRef}
394+
style={mirrorStyle.value}
395+
class={`${prefixCls}-measure`}
403396
>
404-
<span>@</span>
405-
</Trigger>
406-
</div>
407-
)}
397+
{computedValue.value?.slice(0, measureInfo.value.location)}
398+
<Trigger
399+
v-slots={{ content: renderDropdown }}
400+
trigger="focus"
401+
position="bl"
402+
popupOffset={4}
403+
preventFocus={true}
404+
popupVisible={computedPopupVisible.value}
405+
clickToClose={false}
406+
onPopupVisibleChange={handlePopupVisibleChange}
407+
>
408+
<span>@</span>
409+
</Trigger>
410+
</div>
411+
)}
408412
</div>
409413
);
410414
}

packages/web-vue/global.d.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
1+
import type { NativeElements, ReservedProps, VNode } from '@vue/runtime-dom';
2+
13
declare module '*.vue' {
2-
import { DefineComponent } from 'vue';
4+
import type { DefineComponent } from 'vue';
35
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
46
const component: DefineComponent<{}, {}, any>;
57
export default component;
68
}
79

10+
declare global {
11+
namespace JSX {
12+
export type Element = VNode;
13+
export interface ElementClass {
14+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
15+
$props: {};
16+
}
17+
export interface ElementAttributesProperty {
18+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
19+
$props: {};
20+
}
21+
export interface IntrinsicElements extends NativeElements {
22+
[name: string]: any;
23+
}
24+
export type IntrinsicAttributes = ReservedProps;
25+
}
26+
}
27+
828
declare module '*.less';

packages/web-vue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"lint-staged": "npx lint-staged"
5050
},
5151
"peerDependencies": {
52-
"vue": "^3.1.0"
52+
"vue": ">=3.1.0"
5353
},
5454
"lint-staged": {
5555
"*.{js,ts,jsx,tsx,vue}": [

packages/web-vue/tsconfig.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@
99
"allowJs": true,
1010
"isolatedModules": true,
1111
"esModuleInterop": true,
12-
"jsx": "preserve"
13-
}
12+
"jsx": "preserve",
13+
"jsxImportSource": "vue",
14+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
15+
"skipLibCheck": true,
16+
"resolveJsonModule": true,
17+
},
18+
"include": [
19+
"components/**/*",
20+
"icon/**/*",
21+
"*.d.ts"
22+
],
23+
"exclude": [
24+
"node_modules",
25+
"dist",
26+
"lib",
27+
"es",
28+
"json",
29+
"**/__tests__/**/*"
30+
]
1431
}

0 commit comments

Comments
 (0)