Skip to content

Commit 543eaec

Browse files
committed
types: remove unnecessary any type annotations
1 parent 17e7fcd commit 543eaec

File tree

8 files changed

+23
-20
lines changed

8 files changed

+23
-20
lines changed

src/editor/core/command/CommandAdapt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export class CommandAdapt {
319319
painterStyleKeys.forEach(p => {
320320
const key = p as keyof typeof ElementStyleKey
321321
if (painterStyle[key] === undefined) {
322-
painterStyle[key] = s[key] as any
322+
Reflect.set(painterStyle, key, s[key])
323323
}
324324
})
325325
})

src/editor/core/draw/particle/date/DatePicker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface IDatePickerLang {
2828
}
2929

3030
export interface IDatePickerOption {
31-
onSubmit?: (date: string) => any
31+
onSubmit?: (date: string) => void
3232
}
3333

3434
interface IDatePickerDom {

src/editor/core/event/CanvasEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export class CanvasEvent {
124124
selection.forEach(s => {
125125
painterStyleKeys.forEach(pKey => {
126126
const key = pKey as keyof typeof ElementStyleKey
127-
s[key] = painterStyle[key] as any
127+
Reflect.set(s, key, painterStyle[key])
128128
})
129129
})
130130
this.draw.render({ isSetCursor: false })

src/editor/core/event/GlobalEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class GlobalEvent {
7777
const pageList = this.draw.getPageList()
7878
const innerEditorDom = findParent(
7979
target,
80-
(node: any) => pageList.includes(node),
80+
(node: HTMLCanvasElement) => pageList.includes(node),
8181
true
8282
)
8383
if (innerEditorDom) return

src/editor/interface/Plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Editor from '..'
22

3-
export type PluginFunction<Options> = (editor: Editor, options?: Options) => any
3+
export type PluginFunction<Options> = (editor: Editor, options?: Options) => void
44

55
export type UsePlugin = <Options>(
66
pluginFunction: PluginFunction<Options>,

src/editor/interface/contextmenu/ContextMenu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface IRegisterContextMenu {
2828
shortCut?: string
2929
disable?: boolean
3030
when?: (payload: IContextMenuContext) => boolean
31-
callback?: (command: Command, context: IContextMenuContext) => any
31+
callback?: (command: Command, context: IContextMenuContext) => void
3232
childMenus?: IRegisterContextMenu[]
3333
}
3434

src/editor/interface/shortcut/Shortcut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export interface IRegisterShortcut {
99
shift?: boolean
1010
alt?: boolean // windows:alt || mac:option
1111
isGlobal?: boolean
12-
callback?: (command: Command) => any
12+
callback?: (command: Command) => void
1313
disable?: boolean
1414
}

src/editor/utils/index.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ export function deepCloneOmitKeys<T, K>(obj: T, omitKeys: (keyof K)[]): T {
4242
if (!obj || typeof obj !== 'object') {
4343
return obj
4444
}
45-
let newObj: any = {}
45+
let newObj = {} as T
4646
if (Array.isArray(obj)) {
47-
newObj = obj.map(item => deepCloneOmitKeys(item, omitKeys))
47+
newObj = obj.map(item => deepCloneOmitKeys(item, omitKeys)) as T
4848
} else {
4949
// prettier-ignore
50-
(Object.keys(obj) as (keyof K)[]).forEach(key => {
51-
if (omitKeys.includes(key)) return
52-
return (newObj[key] = deepCloneOmitKeys((obj[key as unknown as keyof T] ), omitKeys))
50+
(Object.keys(obj) as (keyof T)[]).forEach(key => {
51+
if (omitKeys.includes(key as unknown as keyof K)) return
52+
newObj[key] = deepCloneOmitKeys(obj[key] , omitKeys)
5353
})
5454
}
5555
return newObj
@@ -62,13 +62,13 @@ export function deepClone<T>(obj: T): T {
6262
if (!obj || typeof obj !== 'object') {
6363
return obj
6464
}
65-
let newObj: any = {}
65+
let newObj = {} as T
6666
if (Array.isArray(obj)) {
67-
newObj = obj.map(item => deepClone(item))
67+
newObj = obj.map(item => deepClone(item)) as T
6868
} else {
6969
// prettier-ignore
7070
(Object.keys(obj) as (keyof T)[]).forEach(key => {
71-
return (newObj[key] = deepClone(obj[key]))
71+
newObj[key] = deepClone(obj[key])
7272
})
7373
}
7474
return newObj
@@ -150,14 +150,14 @@ export function downloadFile(href: string, fileName: string) {
150150
a.click()
151151
}
152152

153-
export function threeClick(dom: HTMLElement, fn: (evt: MouseEvent) => any) {
153+
export function threeClick(dom: HTMLElement, fn: (evt: MouseEvent) => void) {
154154
nClickEvent(3, dom, fn)
155155
}
156156

157157
function nClickEvent(
158158
n: number,
159159
dom: HTMLElement,
160-
fn: (evt: MouseEvent) => any
160+
fn: (evt: MouseEvent) => void
161161
) {
162162
let count = 0
163163
let lastTime = 0
@@ -400,12 +400,16 @@ export function indexOf(
400400
return { index: start, length: 0 }
401401
}
402402
const index = source.indexOf(search, start)
403-
return index === -1 ? { index: -1, length: 0 } : { index, length: search.length }
403+
return index === -1
404+
? { index: -1, length: 0 }
405+
: { index, length: search.length }
404406
}
405407

406408
// 确保正则包含 "g" 才可以设置 lastIndex,从而从任意位置开始搜索
407409
const originalFlags = search.flags
408-
const flags = originalFlags.includes('g') ? originalFlags : originalFlags + 'g'
410+
const flags = originalFlags.includes('g')
411+
? originalFlags
412+
: originalFlags + 'g'
409413
const re = new RegExp(search.source, flags)
410414
re.lastIndex = start
411415
const match = re.exec(source)
@@ -414,4 +418,3 @@ export function indexOf(
414418
}
415419
return { index: match.index, length: match[0].length }
416420
}
417-

0 commit comments

Comments
 (0)