feat: 为 tabbar 的 pagePath 添加明确的联合类型

This commit is contained in:
Utopia
2025-10-29 14:08:40 +08:00
parent b7bf251254
commit b6415c8282
2 changed files with 11 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
import type { TabBar } from '@uni-helper/vite-plugin-uni-pages'
import type { RemoveLeadingSlashFromUnion } from '@/typings'
/**
* tabbar 选择的策略,更详细的介绍见 tabbar.md 文件
@@ -22,7 +23,9 @@ export const TABBAR_STRATEGY_MAP = {
// 如果是使用 CUSTOM_TABBAR(2,3),只需要配置 customTabbarListnativeTabbarList 不生效
export const selectedTabbarStrategy = TABBAR_STRATEGY_MAP.CUSTOM_TABBAR_WITH_CACHE
type NativeTabBarItem = TabBar['list'][number]
type NativeTabBarItem = TabBar['list'][number] & {
pagePath: RemoveLeadingSlashFromUnion<_LocationUrl>
}
// TODO: 2/3. 使用 NATIVE_TABBAR 时,更新下面的 tabbar 配置
export const nativeTabbarList: NativeTabBarItem[] = [
@@ -45,7 +48,7 @@ export type CustomTabBarItemBadge = number | 'dot'
export interface CustomTabBarItem {
text: string
pagePath: string
pagePath: RemoveLeadingSlashFromUnion<_LocationUrl>
iconType: 'uiLib' | 'unocss' | 'iconfont' | 'image' // 不建议用 image 模式需要配置2张图
icon: any // 其实是 string 类型,这里是为了避免 ts 报错 (tabbar/index.vue 里面 uni-icons 那行)
iconActive?: string // 只有在 image 模式下才需要传递的是高亮的图片PS 不建议用 image 模式)

View File

@@ -13,3 +13,9 @@ export interface IUniUploadFileOptions {
name?: string
formData?: any
}
/** 工具类型:删除字符串开头的第一个斜杠 */
export type RemoveLeadingSlash<S extends string> = S extends `/${infer Rest}` ? Rest : S
/** 工具类型:删除联合类型中每个字符串的第一个斜杠 */
export type RemoveLeadingSlashFromUnion<T extends string> = T extends any ? RemoveLeadingSlash<T> : never