Skip to content

Commit

Permalink
types: enable @typescripteslint/array-type (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
LoTwT authored Nov 20, 2024
1 parent 6b680f1 commit e695f25
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 12 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"root": true,
"ignorePatterns": ["lib", "coverage", "docs/.vitepress/cache", "docs/.vitepress/dist"],
"extends": ["@varlet"]
"extends": ["@varlet"],
"rules": {
"@typescript-eslint/array-type": "error"
}
}
4 changes: 2 additions & 2 deletions src/array/find.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function find<T>(
arr: Array<T>,
fn: (item: T, index: number, array: Array<T>) => any,
arr: T[],
fn: (item: T, index: number, array: T[]) => any,
from: 'start' | 'end' = 'start',
): [T, number] | [null, -1] {
let i = from === 'start' ? 0 : arr.length - 1
Expand Down
2 changes: 1 addition & 1 deletion src/array/removeArrayBlank.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function removeArrayBlank<T>(arr: Array<T | null | undefined>) {
export function removeArrayBlank<T>(arr: (T | null | undefined)[]) {
return arr.filter((item) => item != null) as T[]
}
2 changes: 1 addition & 1 deletion src/array/removeArrayEmpty.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function removeArrayEmpty<T>(arr: Array<T | null | undefined | ''>) {
export function removeArrayEmpty<T>(arr: (T | null | undefined | '')[]) {
return arr.filter((item) => item != null && item !== '') as T[]
}
2 changes: 1 addition & 1 deletion src/array/removeItem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function removeItem<T>(arr: Array<T>, item: T) {
export function removeItem<T>(arr: T[], item: T) {
if (arr.length) {
const index: number = arr.indexOf(item)
if (index > -1) {
Expand Down
2 changes: 1 addition & 1 deletion src/array/toggleItem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { removeItem } from './removeItem'

export function toggleItem<T>(arr: Array<T>, item: T) {
export function toggleItem<T>(arr: T[], item: T) {
arr.includes(item) ? removeItem(arr, item) : arr.push(item)
return arr
}
2 changes: 1 addition & 1 deletion src/general/isArray.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function isArray(val: unknown): val is Array<any> {
export function isArray(val: unknown): val is any[] {
return Array.isArray(val)
}
2 changes: 1 addition & 1 deletion src/general/isNonEmptyArray.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isArray } from './isArray'

export function isNonEmptyArray(val: unknown): val is Array<any> {
export function isNonEmptyArray(val: unknown): val is any[] {
return isArray(val) && !!val.length
}
2 changes: 1 addition & 1 deletion src/number/clampArrayRange.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { clamp } from './clamp'

export function clampArrayRange(index: number, arr: Array<unknown>) {
export function clampArrayRange(index: number, arr: unknown[]) {
return clamp(index, 0, arr.length - 1)
}
4 changes: 2 additions & 2 deletions src/util/getAllParentScroller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isWindow } from '../general'
import { getParentScroller } from './getParentScroller'

export function getAllParentScroller(el: HTMLElement): Array<HTMLElement | Window> {
const allParentScroller: Array<HTMLElement | Window> = []
export function getAllParentScroller(el: HTMLElement): (HTMLElement | Window)[] {
const allParentScroller: (HTMLElement | Window)[] = []
let element: HTMLElement | Window = el

while (!isWindow(element)) {
Expand Down

0 comments on commit e695f25

Please sign in to comment.