chore: enable noUncheckedIndexedAccess, better type check (#2608)
This commit is contained in:
@@ -12,7 +12,7 @@ export const isCJKChar = (char: string): boolean => {
|
||||
|
||||
export const getNameInitials = (name?: string): string => {
|
||||
if (!name) return ""
|
||||
const first = name[0]
|
||||
const first = name[0]!
|
||||
const second = name[1]
|
||||
|
||||
if (isCJKChar(first)) return first
|
||||
|
||||
@@ -24,7 +24,19 @@ export function stringToHue(str: string) {
|
||||
}
|
||||
|
||||
const memoMap = {} as Record<string, ReturnType<typeof getColorScheme>>
|
||||
export const getColorScheme = (hue?: number, memo?: boolean) => {
|
||||
export const getColorScheme = (
|
||||
hue?: number,
|
||||
memo?: boolean,
|
||||
): {
|
||||
light: {
|
||||
accent: string
|
||||
background: string
|
||||
}
|
||||
dark: {
|
||||
accent: string
|
||||
background: string
|
||||
}
|
||||
} => {
|
||||
const baseHue = hue ?? Math.floor(Math.random() * 361)
|
||||
if (baseHue && memo) {
|
||||
if (memoMap[baseHue]) {
|
||||
@@ -70,14 +82,14 @@ const adjustColorTowardsTarget = (color: string, targetColor: string, factor: nu
|
||||
const [r1, g1, b1] = hexToRgb(color)
|
||||
const [r2, g2, b2] = hexToRgb(targetColor)
|
||||
|
||||
const r = Math.round(lerp(r1, r2, factor))
|
||||
const g = Math.round(lerp(g1, g2, factor))
|
||||
const b = Math.round(lerp(b1, b2, factor))
|
||||
const r = Math.round(lerp(r1!, r2!, factor))
|
||||
const g = Math.round(lerp(g1!, g2!, factor))
|
||||
const b = Math.round(lerp(b1!, b2!, factor))
|
||||
|
||||
return rgbToHex(r, g, b)
|
||||
}
|
||||
|
||||
export const getBackgroundGradient = (seed?: Nullable<string>) => {
|
||||
export const getBackgroundGradient = (seed?: string | null | undefined) => {
|
||||
const nextSeed = seed ?? Math.random().toString(36).slice(7)
|
||||
|
||||
const bgAccent = uniqolor(nextSeed, {
|
||||
@@ -125,7 +137,7 @@ export function getDominantColor(imageObject: HTMLImageElement) {
|
||||
// get pixel color
|
||||
const i = ctx.getImageData(0, 0, 1, 1).data
|
||||
|
||||
return `#${((1 << 24) + (i[0] << 16) + (i[1] << 8) + i[2]).toString(16).slice(1)}`
|
||||
return `#${((1 << 24) + (i[0]! << 16) + (i[1]! << 8) + i[2]!).toString(16).slice(1)}`
|
||||
}
|
||||
|
||||
export const isHexColor = (color: string) => {
|
||||
|
||||
@@ -30,7 +30,7 @@ class EventBusStatic<E extends AnyObject> {
|
||||
return this.unsubscribe.bind(this, event as string, handler)
|
||||
}
|
||||
|
||||
unsubscribe(event: string, handler: (e: any) => void) {
|
||||
unsubscribe(_event: string, handler: (e: any) => void) {
|
||||
window.removeEventListener(EventBusEvent.type, handler)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ export const createAtomHooks = <T>(atom: PrimitiveAtom<T>) => {
|
||||
return result as any as Result
|
||||
}
|
||||
|
||||
const noop = []
|
||||
const noop: any[] = []
|
||||
const createAtomSelector = <T>(atom: Atom<T>) => {
|
||||
const useHook = <R>(selector: (a: T) => R, deps: any[] = noop) =>
|
||||
useAtomValue(
|
||||
|
||||
@@ -132,7 +132,7 @@ export const parseRegexpPathParams = (
|
||||
}
|
||||
}
|
||||
case "group": {
|
||||
if ("name" in token.tokens[1]) {
|
||||
if ("name" in token.tokens[1]!) {
|
||||
return {
|
||||
name: token.tokens[1].name,
|
||||
optional: true,
|
||||
|
||||
@@ -98,7 +98,7 @@ export function buildGlobRoutes(glob: Record<string, () => Promise<any>>): Route
|
||||
// }
|
||||
|
||||
const childrenChildren: RouteObject[] = []
|
||||
dtsRoutes(`${segmentPathKey}/`, childrenChildren, paths[key], parentPath)
|
||||
dtsRoutes(`${segmentPathKey}/`, childrenChildren, paths[key]!, parentPath)
|
||||
children.push({
|
||||
path: "",
|
||||
lazy: globGetter,
|
||||
@@ -131,7 +131,7 @@ export function buildGlobRoutes(glob: Record<string, () => Promise<any>>): Route
|
||||
})
|
||||
break
|
||||
} else {
|
||||
const content = paths[key]
|
||||
const content = paths[key]!
|
||||
const hasChild = Object.keys(content).length > 0
|
||||
|
||||
const normalizeKey = normalizePathKey(key)
|
||||
@@ -158,7 +158,7 @@ export function buildGlobRoutes(glob: Record<string, () => Promise<any>>): Route
|
||||
} else {
|
||||
const childrenChildren: RouteObject[] = []
|
||||
const fullPath = `${parentPath}/${normalizeKey}`
|
||||
dtsRoutes(`${segmentPathKey}/`, childrenChildren, paths[key], fullPath)
|
||||
dtsRoutes(`${segmentPathKey}/`, childrenChildren, paths[key]!, fullPath)
|
||||
children.push({
|
||||
path: normalizeKey,
|
||||
children: childrenChildren,
|
||||
|
||||
@@ -92,7 +92,7 @@ export const isSafari = once(() => {
|
||||
})
|
||||
|
||||
// eslint-disable-next-line no-control-regex
|
||||
export const isASCII = (str) => /^[\u0000-\u007F]*$/.test(str)
|
||||
export const isASCII = (str: string) => /^[\u0000-\u007F]*$/.test(str)
|
||||
|
||||
const EPOCH = 1712546615000n // follow repo created
|
||||
const MAX_TIMESTAMP_BITS = 41n // Maximum number of bits typically used for timestamp
|
||||
@@ -149,7 +149,7 @@ export const capitalizeFirstLetter = (string: string) =>
|
||||
string.charAt(0).toUpperCase() + string.slice(1)
|
||||
|
||||
export const omitObjectUndefinedValue = (obj: Record<string, any>) => {
|
||||
const newObj = {}
|
||||
const newObj = {} as any
|
||||
for (const key in obj) {
|
||||
if (obj[key] !== undefined) {
|
||||
newObj[key] = obj[key]
|
||||
@@ -232,13 +232,13 @@ export function isKeyForMultiSelectPressed(e: MouseEvent) {
|
||||
export const toScientificNotation = (num: string, threshold: number) => {
|
||||
const cleanNum = num.replaceAll(",", "")
|
||||
const [intPart, decimalPart = ""] = cleanNum.split(".")
|
||||
const numLength = intPart.replace(/^0+/, "").length
|
||||
const numLength = intPart!.replace(/^0+/, "").length
|
||||
|
||||
if (numLength > threshold) {
|
||||
const fullNum = intPart + decimalPart
|
||||
const firstDigit = fullNum.match(/[1-9]/)?.[0] || "0"
|
||||
const position = fullNum.indexOf(firstDigit)
|
||||
const exponent = intPart.length - position - 1
|
||||
const exponent = intPart!.length - position - 1
|
||||
|
||||
const significand = fullNum.slice(position, position + 3)
|
||||
const formattedSignificand = `${significand[0]}.${significand.slice(1)}`
|
||||
|
||||
Reference in New Issue
Block a user