mit einem Klick
fix-type-error
修复 TypeScript 类型错误,优化类型写法的通用子代理。
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Menü
修复 TypeScript 类型错误,优化类型写法的通用子代理。
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Basierend auf der SOC-Berufsklassifikation
使用 Nitro v3 框架和 H3 编写服务端 API 的技能。适用于后端接口开发、Mock 数据迁移到 Neon 数据库、以及编写符合 Drizzle ORM 标准的查询逻辑。当需要开发新的 CRUD 接口或修复现有后端逻辑时使用此技能。
规范类型项目(apps/type)的代码组织方式、导出语法和文件结构。用于解决类型导出冲突、创建统一导出入口、处理重复导出等问题。适用于类型项目开发、类型错误修复、代码规范实施场景。在处理类型项目的代码写法时,请使用本技能。
当你修改数据库结构或种子生成脚本时,请务必阅读并遵循此指南,以防止性能问题、数据一致性崩溃和部署失败。新 Schema 应在 apps/type 中创建。
数据库 Schema 变更时的全项目同步检查清单。当修改 apps/type 中 schema.ts 的表字段、新增数据库表、或删除表时,使用此技能确保类型项目、数据库迁移、后端接口、前端页面、种子数据和技能文档全部同步更新,避免遗漏。
当用户要求在 bug 已经定位并修复后,记录排错经验、事故结论、AI 记忆更新、复盘摘要或本地 MCP 记忆时使用。这个技能只负责沉淀"发生了什么、为什么会发生、如何修好、以后要记住什么",不要把它用于实际修复 bug。
新建公共组件规范专家 - 指导在 src/components/common 目录下创建符合项目规范的公共组件,包括文件结构、TypeScript 类型、Vue 组件、文档和测试页面。 触发条件(满足任意一项即触发): - 任务包含"新建组件"、"公共组件"、"common 组件"、"创建组件"等关键词 - 需要在 src/components/common 目录下创建新组件 - 需要创建可复用的业务组件(如表单分区标题、操作按钮组、信息展示卡片) - 需要编写组件的 TypeScript 类型定义 - 需要编写组件使用文档(index.md) - 需要创建组件测试页面(src/pages/test-use/) - 用户提及"组件规范"、"组件文档"、"组件测试"等关键词 必须协同的技能: - beautiful-component-design(组件美化时)- 图标、响应式设计、表单分区标题 - component-migration(从旧组件迁移时)- ColorUI → wot-design-uni - use-wd-form(组件内包含表单时)- 表单结构、wd-picker、校验规则 禁止事项: - 禁止在 components 目录外创建公共组件 - 禁止不编写组件文档(index.md) - 禁止不提供使用示例和测试页面 - 禁止组件命名不规范(必须使用短横线命名法) - 禁止不定义 TypeScript 类型(types.ts) - 禁止在组件文件顶部不添加说明注释 - 禁止不使用 withDefaults 设置 props 默认值 覆盖场景:所有需要跨页面复用的业务组件,包括表单分区标题(FormSectionTitle)、操作按钮组(ActivityActions)、信息展示卡片(ActivityInfo)、加载状态组件(ZPagingLoading)等。
| name | fix-type-error |
| description | 修复 TypeScript 类型错误,优化类型写法的通用子代理。 |
优先使用官方类型检查命令:
# 完整类型检查
pnpm -F @01s-11comm/admin typecheck
pnpm -F @01s-11comm/type typecheck
# 或分别运行 TypeScript 和 Vue TypeScript 检查
npx tsc --noEmit --skipLibCheck
npx vue-tsc --noEmit --skipLibCheck
当项目中存在大量类型错误时,使用筛选方法:
# 筛选特定模块的错误
npx vue-tsc --noEmit --skipLibCheck 2>&1 | grep -i "模块名"
# 例如:筛选 issues 相关的错误
npx vue-tsc --noEmit --skipLibCheck 2>&1 | grep -i "issues\|工单池"
TS2304: 找不到名称TS2322: 类型不匹配TS2440: 导入冲突TS2345: 参数类型不兼容表现: Import declaration conflicts with local declaration
解决方案:
示例:
// ❌ 错误:导入冲突
import { type 工单池_列表查询_VO } from "./test-data";
interface 工单池_列表查询_VO { ... }
// ✅ 正确:移除导入,使用本地定义
interface 工单池_列表查询_VO { ... }
表现: Cannot find name 'xxx'
解决方案:
自动导入检查位置:
build/plugins/unplugin-auto-import/index.ts请务必要完整阅读 apps\admin\build\plugins\unplugin-auto-import\index.ts 自动导入文件,了解清楚那些类型属于自动导入的,以确保这些自动导入的类型、函数、变量。不会被使用错误的模块导入。
常见自动导入项:
lodash-es: merge, isEmpty 等vue: 所有 Vue 组合式 APIplus-pro-components: FieldValues, PlusColumn 等src/composables/**/*.ts: 所有自定义组合式函数表现: Type 'xxx' is not assignable to type 'yyy'
解决方案:
示例:
// ❌ 错误:类型不匹配
openDialog({ mode: "view", row }); // Mode 类型为 "add" | "edit" | "info"
// ✅ 正确:使用正确的类型值
openDialog({ mode: "info", row });
表现: 组合式函数内部使用未导入的 API
解决方案:
示例:
// ❌ 错误:onMounted 未导入
export function usePlusFormReset(plusFormInstance: any) {
onMounted(() => { ... }); // onMounted 未导入
}
// ✅ 正确:导入 onMounted
import { onMounted } from "vue";
export function usePlusFormReset(plusFormInstance: any) {
onMounted(() => { ... });
}
// ❌ 错误 从不存在的 `vue-macro` 模块内导入模块
import { cloneDeep, sleep, useToggle } from "vue-macro";
// ✅ 正确 在正确的模块内导入工具
import { cloneDeep } from "@pureadmin/utils";
import { sleep } from "@antfu/utils";
import { useToggle } from "@vueuse/core";
PlusFormRules 类型// ❌ 错误 从 `plus-pro-components` 模块内导入 PlusFormRules 类型
import { type OptionsType, type FieldValues, type PlusColumn, type PlusFormRules } from "plus-pro-components";
// ✅ 正确 在 @/config/constant 全局常量内, 导入 PlusFormRules 类型
import { type FieldValues, type PlusColumn } from "plus-pro-components";
import type { PlusFormRules } from "@/config/constant";
TableColumnList 类型// ❌ 错误 从 `@pureadmin/table` 模块内导入了不存在的 `TableColumnList` 类型
import type { TableColumnList } from "@pureadmin/table";
// ✅ 正确 无需手动导入, TableColumnList 类型是全局类型,不需要我们手动导入
不好的类型写法如下:
/**
* @description 商户管理员表单 props Merchant admin form props
* @description
* 为了避免全局类型冲突 故设计较长的类型名称
* To avoid global type conflicts, a longer type name is designed
*/
export interface MerchantAdminFormProps {
/** 表单数据 Form data */
form: MerchantAdminFormVO;
/** 表单组件重置时默认使用的对象 Default object used when form component is reset */
defaultValues: MerchantAdminFormVO;
/** 表单模式 Form mode */
mode?: "add" | "edit" | "info";
}
我们不应该手写类型 mode?: "add" | "edit" | "info"; ,这很容易出错。相反,我们应该使用导入的 mode 类型,来完成类型优化。好的类型写法如下:
Mode 是一个在客户端代码内全局导入的类型,直接使用即可,无需考虑手动导入。
/**
* @description 商户管理员表单 props Merchant admin form props
* @description
* 为了避免全局类型冲突 故设计较长的类型名称
* To avoid global type conflicts, a longer type name is designed
*/
export interface MerchantAdminFormProps {
/** 表单数据 Form data */
form: MerchantAdminFormVO;
/** 表单组件重置时默认使用的对象 Default object used when form component is reset */
defaultValues: MerchantAdminFormVO;
/** 表单模式 Form mode */
mode?: Mode;
}
mode?: "add" | "edit" | "view"; 类型,使用全局的客户端类型 Modemode?: "add" | "edit" | "view"; 是错误的。mode?: "add" | "edit" | "info"; 才是正确的。我们不存在错误的 view 类型。mode?: "add" | "edit" | "info"; 类型。在客户端代码,即 apps\admin\src 目录内,我们应该直接使用 mode?: Mode; 的写法。其中 Mode 是客户端代码内全局导入的类型。直接使用即可。类型项目内,出现上述写法,请你将这个错误迁移位置的类型,根据业务路径,迁移回到后台项目的对应业务路径的 form.ts 文件内。类型项目是不应该出现这样的写法的,出现的原因是因为有工具错误的迁移该类型到类型项目目录下了,所以需要你将该类型迁移到正确的位置。/** 向后兼容:巡检方式 / Backward compatibility: PatrolMethodType */
export type 巡检方式 = PatrolMethodType;
/** 向后兼容:任务状态 / Backward compatibility: TaskStatusType */
export type 任务状态 = TaskStatusType;
/** 向后兼容:巡检点状态 / Backward compatibility: PatrolPointStatusType */
export type 巡检点状态 = PatrolPointStatusType;
/** 向后兼容:巡查明细表单_VO / Backward compatibility: 巡查明细表单_VO */
export type 巡查明细表单_VO = PatrolDetailFormVO;
/** 向后兼容:巡查明细表单Props / Backward compatibility: 巡查明细表单Props */
export type 巡查明细表单Props = PatrolDetailFormProps;
以下代码是错误的,你不应该主动导入任何 getRouteRank 函数。这个函数是全局自动导入的,不需要你手动导入。
getRouteRank 是在宏上的使用的。
// 错误的导入 应该删除
import { getRouteRank } from "@/router/rank";
plus-pro-components 模块的全局类型请注意,以下即可类型均来自于 plus-pro-components 模块,他们都是客户端代码内全局通用的类型。
FieldValuesPlusSearchPropsPlusColumn这些类型都在 apps\admin\build\plugins\unplugin-auto-import\index.ts 自动导入插件内有声明。
这是常见错误。如果你需要处理类型错误而导入全局类型,请在 plus-pro-components 模块内导入正确的类型。
// 正确的导入路径
import type { FieldValues } from "plus-pro-components";
在客户端代码内,类型 TableColumnList 来自于全局类型文件 apps\admin\types\global.d.ts 。不应该手动导入。
// 该写法是错误的 不应该去任何模块导入 TableColumnList 类型
import type { TableColumnList } from "@pureadmin/table";
// 该写法是错误的 不应该去任何模块导入 PureTableBarProps 类型。 不应该去任何 `@pureadmin` 模块内导入该类型
import type { PureTableBarProps } from "@pureadmin/table";
背景说明:
对于形如 xxxxxxFormProps 格式的类型,这些类型都是表单弹框类型,不是业务类型。你不应该将弹框组件的类型迁移到类型项目内。
错误示例:
// apps\type\src\business\property-manage\report-manage\repair-reports-summary-table.ts
/**
* 报修汇总表表单属性
* Repair reports summary table form props
*/
export interface RepairReportsSummaryTableFormProps {
/** 表单数据 Form data */
form: RepairReportsSummaryTableFormData;
/** 表单组件重置时默认使用的对象 Default object used when form component is reset */
defaultValues: RepairReportsSummaryTableFormData;
/** 表单模式 Form mode */
mode?: "add" | "edit" | "info";
}
正确做法:
form.ts 内。form.ts 内导入固定写法的 import { type Mode } from "@/composables/use-mode"; 类型。mode 字段的类型,统一换成 Mode 类型。// apps\admin\src\pages\property-manage\report-manage\repair-reports-summary-table\components\form.ts
import { type Mode } from "@/composables/use-mode";
/**
* 报修汇总表表单属性
* Repair reports summary table form props
*/
export interface RepairReportsSummaryTableFormProps {
/** 表单数据 Form data */
form: RepairReportsSummaryTableFormData;
/** 表单组件重置时默认使用的对象 Default object used when form component is reset */
defaultValues: RepairReportsSummaryTableFormData;
/** 表单模式 Form mode */
mode?: Mode;
}
关键要点:
form.ts 文件中,而不是类型项目中Mode 类型是客户端代码内全局导入的类型,直接使用即可现象: Property 'request' does not exist on type 'H3Event'
根因: Nitro v3 升级到 H3 v2,H3Event 不再暴露底层的 request / response 对象
正确写法:
// ❌ 旧写法(H3 v1)
const ip = event.request.headers.get("x-forwarded-for");
event.response.headers.set("X-RateLimit-Limit", "100");
// ✅ 新写法(H3 v2)
import { getRequestHeader, setResponseHeader } from "nitro/h3";
const ip = getRequestHeader(event, "x-forwarded-for");
setResponseHeader(event, "X-RateLimit-Limit", "100");
现象: NeonAuth 不接受无参数,导致类型报错
正确写法:
// ❌ 错误
import type { NeonAuth } from "@neondatabase/auth";
export type AuthClientType = NeonAuth;
// ✅ 正确
import { createAuthClient } from "@neondatabase/auth";
import type { NeonAuthPublicApi } from "@neondatabase/auth";
export type AuthClientType = NeonAuthPublicApi<any>;
现象: res.success 报 "Property 'success' does not exist"
根因: 错误地从 @ruan-cat/utils/vueuse 导入 JsonVO(无 success 字段)
两个 JsonVO 的对比:
| 来源 | 字段 |
|---|---|
| @ruan-cat/utils/vueuse | code, message, data |
| @01s-11comm/type | code, message, data, success?, error?, stack?, timestamp? |
正确写法:
// ❌ 错误
import type { JsonVO } from "@ruan-cat/utils/vueuse";
// ✅ 正确
import type { JsonVO } from "@01s-11comm/type";
现象: Argument of type 'string' is not assignable to parameter of type 'DataInfo<number>'
字段映射(Neon Auth → DataInfo):
| Neon Auth 响应字段 | DataInfo 字段 |
|---|---|
| data.token | accessToken |
| data.refreshToken | refreshToken |
| data.expiresIn | expires |
正确写法:
// ❌ 错误
setToken(data.token);
// ✅ 正确
setToken({
accessToken: data.token,
refreshToken: data.refreshToken,
expires: data.expiresIn,
} as DataInfo<number>);
现象: Object literal may only specify known properties, and 'post' does not exist in type 'EventHandlerObject'
根因: Nitro v3 文件路由通过文件名区分 HTTP 方法
正确写法:
// ❌ 错误
export default defineHandler({
async post(event, body) { ... },
});
// ✅ 正确
export default defineHandler(async (event) => {
const body = await readBody<MyInput>(event);
return handleXxx(event, body);
});
现象: Expected 1 arguments, but got 0
根因: Cloudflare Worker 环境中,环境变量只在 request handler 内部可用
设计原则: 所有需要调用数据库的服务端工具函数,必须将 event: H3Event 作为第一个参数
正确写法:
// ❌ 错误
export async function getMigrationStats() {
const db = useDb();
}
// ✅ 正确
export async function getMigrationStats(event: H3Event) {
const db = useDb(event);
}
现象: Property 'path' does not exist on type 'HTTPEvent'
正确写法:
import type { H3Event } from "nitro/h3";
nitroApp.hooks.hook("request", async (rawEvent) => {
const event = rawEvent as H3Event;
const path = event.path;
});
现象: Type 'string' is not assignable to type 'RuleType'
正确写法:
// ❌ 类型推断为 string
{ type: "email", message: "请输入正确邮箱", trigger: "blur" }
// ✅ 使用 as const
{ type: "email" as const, message: "请输入正确邮箱", trigger: "blur" }
现象: TS2352: Conversion of type 'readonly [...]' to type 'string[]' may be a mistake
正确写法:
// ❌ TypeScript 认为不安全
(BUSINESS_TABLE_GROUPS[group] as string[])
.includes(tableName)(
// ✅ 双重 as
BUSINESS_TABLE_GROUPS[group] as unknown as string[],
)
.includes(tableName);
.values() 报 TS2769:InferInsertModel 排除有默认值的列现象: db.insert(table).values([{ id: ..., ... }]) 报 TS2769: No overload matches this call,id 和其他有默认值/nullable 的列被视为"多余属性"
根因: Drizzle v0.42 的 InferInsertModel 类型推导会将所有带 default/$defaultFn/defaultRandom 的列排除在 insert 类型之外。TypeScript 对 "fresh object literal"(直接写在函数参数位置的对象字面量)执行 excess property check,不允许传入类型定义以外的属性。
常见误区(不要踩):
primaryId() 从 defaultRandom() 改为 default(sql...).$defaultFn(...),期望 id 变为可选——无效,Drizzle 对任何有默认值的列都执行相同的类型排除InferInsertModel<T> & { id?: string } 做类型交叉——无效,InferInsertModel 只包含 notNull + 无 default 的列,所有 nullable/有默认值的列同样被排除正确写法:
// ❌ 错误:fresh object literal 直接传入 .values(),触发 excess property check
db.insert(table).values([{ id: sid("scope", "key"), name: "test", status: "active" }]);
// ✅ 正确:用泛型 identity 函数 rows() 打破 fresh literal 标记
import { rows } from "../helpers";
db.insert(table).values(rows([{ id: sid("scope", "key"), name: "test", status: "active" }]));
rows() 实现(在 server/db/seed/helpers.ts):
export function rows<const T extends Record<string, unknown>[]>(data: T): T {
return data;
}
原理: 函数调用边界打破 TypeScript 的 "fresh object literal" 标记,使 .values() 走结构兼容性检查而非严格属性检查。const 类型参数保留字面量类型(见 2.26)。零运行时开销,不使用 as any。
const 类型参数保留枚举字面量现象: 使用 rows<T>(data: T): T(无 const)包装后,pgEnum 列仍然报类型错误——枚举字面量值 "percentage" 被宽化为 string,与 "fixed" | "percentage" | "period" 不匹配
根因: TypeScript 泛型默认会将字符串字面量类型宽化为 string。const 类型参数(<const T>)告诉 TypeScript 保留传入值的字面量类型。
正确写法:
// ❌ 错误:无 const,字面量被宽化
function rows<T extends Record<string, unknown>[]>(data: T): T {
return data;
}
// "percentage" 被推断为 string → 与 pgEnum 联合类型不匹配
// ✅ 正确:const 保留字面量类型
function rows<const T extends Record<string, unknown>[]>(data: T): T {
return data;
}
// "percentage" 被保留为 "percentage" → 与 pgEnum 联合类型匹配
适用范围: 任何需要在函数边界打破 excess property check 同时保留 enum/字面量类型的场景。
本项目配置了强大的自动导入功能,包括:
优势:
test-data.ts 文件中components/form.ts 文件中工单池_列表数据_VO、_数据、_选项 等后缀区分用途usePlusFormReset# 检查特定文件类型
npx tsc --noEmit src/path/to/file.ts --skipLibCheck
# 查看自动导入的生成文件
cat apps/admin/types/auto-imports.d.ts
# 搜索类型定义
grep -r "type.*接口名" src/
typeof 操作符检查变量类型通过遵循这套方法论,可以系统性地处理项目中的类型错误,提高开发效率和代码质量。
文件位置: apps/admin/src/pages/setting-manage/organize-manage/working-schedule/components/form.vue
遇到的问题:
valueType: "time" 类型错误pattern 类型不兼容错误表现:
不能将类型""time""分配给类型"TableValueType | FormItemValueType"
分析思路:
FormItemValueType 包含 'time-picker' 而非 'time'valueType: "time"解决方案:
// ❌ 错误的写法
{
label: "开始时间",
prop: "开始时间",
valueType: "time", // 类型错误
}
// ✅ 正确的写法
{
label: "开始时间",
prop: "开始时间",
valueType: "time-picker", // 正确的类型
}
关键经验:
valueType 有严格的类型定义'time-picker' 而不是 'time'错误表现:
属性"pattern"的类型不兼容。不能将类型"unknown"分配给类型"string | RegExp"
分析思路:
pattern 的类型解决方案:
// ❌ 错误的写法:类型推断失败
const plusFormRules = reactive({
联系电话: [
{ required: true, message: "请输入联系电话", trigger: "blur" },
{ pattern: /^1[3-9]\d{9}$/, message: "请输入正确的手机号码", trigger: "blur" },
],
});
// ✅ 正确的写法:
// 1. 使用全局类型 `PlusFormRules` 来约束变量 plusFormRules 。
// 2. 变量 plusFormRules 使用 ref 而不是 reactive 来定义。
const plusFormRules = ref<PlusFormRules>({
联系电话: [
{ required: true, message: "请输入联系电话", trigger: "blur" },
{ pattern: /^1[3-9]\d{9}$/, message: "请输入正确的手机号码", trigger: "blur" },
],
});
错误表现:
已声明"defaultForm",但从未读取其值
解决方案:
// ❌ 错误:导入但未使用
import { WorkingScheduleFormProps, defaultForm, type 排班表表单_VO } from "./form";
// ✅ 正确:移除未使用的导入
import { WorkingScheduleFormProps, type 排班表表单_VO } from "./form";
使用 IDE 诊断工具验证修复结果:
# 检查特定文件的类型错误
mcp__ide__getDiagnostics(uri="具体文件路径")
# 完整类型检查筛选特定模块
pnpm -F @01s-11comm/admin typecheck 2>&1 | grep -E "working-schedule|error|Error"
FormItemRule 等相关类型as 进行类型断言对于类似的 Plus Pro Components 表单类型错误,可以使用以下修复模板:
import { useTemplateRef, reactive } from "vue";
import type { FormItemRule } from "element-plus";
import type { PlusColumn } from "plus-pro-components";
// 表单项配置模板
const plusFormColumns = ref<PlusColumn[]>([
{
label: "字段名称",
prop: "fieldName",
valueType: "正确的-value-type", // 根据文档选择正确类型
},
]);
// 验证规则模板
const plusFormRules = reactive({
fieldName: [
{ required: true, message: "错误信息", trigger: "blur" } as FormItemRule,
{ pattern: /正则表达式/, message: "格式错误信息", trigger: "blur" } as FormItemRule,
],
});
通过这个实战案例,我们学会了如何系统性地处理第三方组件库的类型错误,特别是在表单组件中常见的类型问题。
JSX.IntrinsicElements 不存在(如 el-button、el-tag 等)。iconify-icon-offline、iconify-icon-online)在 JSX 中类型报错。cellRenderer / headerRenderer 返回值与 TableColumnRenderer 类型不兼容。router.push({ name }) 的 name 与路由联合类型不匹配。// @ts-nocheck,立即消除批量 JSX 报错。ElButton as any、IconifyIconOffline as any,或改回 template 写法。as any 或直接 return h(...),确保返回 VNode | string。router.push({ name: 'XXX' as any }) 保障通过;后续比对路由声明修正 name。类型项目提供的业务类型和公共类型。pnpm -F @01s-11comm/admin typecheck 获取完整清单。ts-nocheck 兜底。ElXxx as any 或转 template。as any。as any 包裹。as any,再排期纠正路由枚举。ts-nocheck 并补全类型。ts-nocheck:为 JSX 组件补类型或改回模板。as any。as any 的依赖。不要去区分是单独导出全部的类型,还是全部的变量。全部都批量导出来。
错误写法:
不要单独的导出类型,直接导出全部的代码。包括类型和变量。
export type * from "./expense-manage";
正确写法:
直接导出全部内容即可。
export * from "./expense-manage";
错误写法:
export type {
PatrolTaskFormVO,
PatrolTaskFormProps,
TaskListItem,
TaskQueryParams,
PatrolTaskListItem,
PatrolTaskQueryParams,
} from "./task";
正确写法:
直接全部导出即可。不要逐个罗列需要被导出的项目。
export * from "./task";
在类型项目内,使用了业务路径来依次组织代码的存放位置。为了逐级获取导出的项目,应该在每一个层级内编写 index.ts 来统一导出全部内容。包括类型和变量。
正确 index.ts 与业务路径的文件组织关系如下:
src/index.ts// apps/type/src/index.ts
// 导出通用类型
export * from "./common";
// 导出业务类型
export * from "./business";
// 导出常量
export * from "./constant";
src/business/index.ts// apps/type/src/business/index.ts
/**
* @file 业务类型统一导出
* @description 导出所有业务模块的类型定义
*/
export * from "./dev-team";
export * from "./operation-team";
export * from "./property-manage";
export * from "./setting-manage";
src/business/property-manage/index.ts// apps/type/src/business/property-manage/index.ts
// 社区管理模块
export * from "./community-manage";
// 房产管理模块
export * from "./house-property-manage";
// 合同管理模块
export * from "./contract-manage";
// 费用管理模块
export * from "./expense-manage";
// 停车管理模块
export * from "./parking-manage";
// 巡检管理模块
export * from "./patrol-manage";
// 报修管理模块
export * from "./repairs-manage";
// 报表管理模块
export * from "./report-manage";
src/business/property-manage/patrol-manage/index.ts// apps/type/src/business/property-manage/patrol-manage/index.ts
export * from "./detail";
export * from "./item";
export * from "./path";
export * from "./plan";
export * from "./point";
export * from "./task";
比如这种错误:
模块 "./community-manage" 已导出一个名为"auditStatusOptions"的成员。请考虑重新显式导出以解决歧义。
模块 "./community-manage" 已导出一个名为"feeTypeOptions"的成员。请考虑重新显式导出以解决歧义。
你不应该使用分散导出的方式来解决类型故障,你应该把这些公共的,相通的类型或变量,统一放在一个文件内导出。
apps/type/src/common/business-options.ts 文件内统一整理,并导出。apps/type/src/common/business-types.ts 文件内统一整理,并导出。对于上述错误,正确的做法是统一放在 apps/type/src/common/business-options.ts 内并导出:
// apps/type/src/common/business-options.ts
/**
* @description 审核状态选项
* Audit status options
*/
export const auditStatusOptions: OptionsType = [
{ label: "待审核", value: "待审核" },
{ label: "已通过", value: "已通过" },
{ label: "已拒绝", value: "已拒绝" },
];
/** 费用项名称选项 Expense item name options */
export const expenseItemNameOptions: OptionsType = [
{ label: "物业费", value: "物业费" },
{ label: "水电费", value: "水电费" },
{ label: "停车费", value: "停车费" },
{ label: "维修费", value: "维修费" },
];
/** 费用类型选项别名 Fee type options alias */
export const feeTypeOptions = expenseTypeOptions;
错误写法:
不要弄这种复杂的逐项导出,阅读很不美观,难以处理。
// 导出通用类型 - 先导出 common
export * from "./common";
// 导出业务类型 - 后导出 business,避免冲突时使用命名导出
export { patrolMethodOptions, patrolPointStatusOptions, returnVisitStatusOptions } from "./common";
// 选择性导出业务模块,避免重复导出
export * from "./business/dev-team";
export * from "./business/operation-team";
export * from "./business/property-manage";
export * from "./business/setting-manage";
// 导出常量
export * from "./constant";
正确写法:
// 导出通用类型
export * from "./common";
// 导出业务类型
export * from "./business";
// 导出常量
export * from "./constant";