mirror of
https://github.com/langgenius/dify.git
synced 2026-05-02 08:28:03 +08:00
refactor(web): improve storage utility type safety with function overloads
Add function overloads to getNumber and getBoolean so they return non-nullable types when a defaultValue is provided. This eliminates the need for non-null assertions at call sites. - Remove unused persist-config.ts (zustand adapter not needed) - Remove ! assertions from layout-slice.ts
This commit is contained in:
@ -73,6 +73,8 @@ function remove(key: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
function getNumber(key: string): number | null
|
||||
function getNumber(key: string, defaultValue: number): number
|
||||
function getNumber(key: string, defaultValue?: number): number | null {
|
||||
const value = get<string | number>(key)
|
||||
if (value === null)
|
||||
@ -82,6 +84,8 @@ function getNumber(key: string, defaultValue?: number): number | null {
|
||||
return Number.isNaN(parsed) ? (defaultValue ?? null) : parsed
|
||||
}
|
||||
|
||||
function getBoolean(key: string): boolean | null
|
||||
function getBoolean(key: string, defaultValue: boolean): boolean
|
||||
function getBoolean(key: string, defaultValue?: boolean): boolean | null {
|
||||
const value = get<string | boolean>(key)
|
||||
if (value === null)
|
||||
|
||||
Reference in New Issue
Block a user