Skyroc Admin Docs
@core 基础设施

@skyroc/types

全局类型声明包,零运行时依赖

概览

包名@skyroc/types
版本1.0.0
依赖无(零依赖)
子入口../types(指向 index.d.ts

@skyroc/types 没有任何运行时值导出,它通过 declare global 注入全局命名空间,所有包都能直接使用这些类型而无需 import。

目录结构

src/
├── api/                # 后端接口契约
│   ├── auth.d.ts
│   ├── common.d.ts
│   ├── route.d.ts
│   ├── service.d.ts
│   └── system-manage.d.ts
├── app/                # 应用内类型
│   ├── common.d.ts
│   ├── global.d.ts
│   ├── menu.d.ts
│   ├── router.d.ts
│   ├── storage.d.ts
│   └── union-key.d.ts
├── locales/i18n.d.ts   # i18n Schema 与 key 推导
├── index.d.ts
└── index.ts            # re-export 各 .d.ts 触发类型合并

全局命名空间

命名空间主要类型用途
Api.AuthLoginParamsLoginTokenUserInfo登录与用户信息
Api.CommonPaginatingQueryRecord<T>CommonRecord<T>EnableStatus分页与通用记录
Api.RouteBackendRouteBackendRouteResponse后端动态路由
Api.ServiceResponse<T>ServiceConfig后端响应 envelope、多 baseURL 配置
Api.SystemManageRoleUserMenuMenuTree系统管理实体
CommonOption<K, M>YesOrNoRecordNullable<T>前端通用工具类型
App.GlobalTabAntdMenuAdminLayout.HeaderProps应用全局
RouterRoutePathRouteIdMetaRouterContext路由(可扩展注册表)
StorageTypeLocalSession本地存储 key(扩展点)
UnionKeyThemeLayoutModeLoginModule联合字面量
I18nSchemaI18nKey$Ti18n 类型推导

可扩展的注册表模式

RouterStorageType 等使用「空接口 + 模块增强」模式,让应用按需扩展:

// 应用侧 src/types/router.d.ts
declare global {
  namespace Router {
    interface RoutePathRegistry {
      '/home': '/home';
      '/manage/user': '/manage/user';
    }
  }
}

这样 Router.RoutePath 就会自动包含应用注册的路径,获得类型安全的导航。StorageType.Local / StorageType.Session 同理,用于约束 localStorage key。

使用

// 无需 import,直接使用全局类型
function getUser(): Api.Auth.UserInfo { /* ... */ }

const option: Common.Option = { label: '启用', value: '1' };

该包无 __tests__(纯类型声明无需运行时测试)。

On this page