refactor: improve type safety across codebase #90

Merged
xiaomo merged 1 commits from refactor/type-safety into main 2026-04-24 12:09:37 +00:00
Owner

What

TypeScript 类型安全优化,消除 codebase 中的类型断言和 as 强制转换。

Why

减少运行时类型安全隐患,让编译器能捕获更多错误。

Changes

文件 变更
core/src/is-plain-record.ts 新增 isPlainRecord() type guard
core/src/config.ts 用 isPlainRecord() 替代手动检查和 as 断言
cli/src/commands/start.ts as any → as unknown as { fd: number }(FFI边界)
cli/src/daemon-client.ts 改善 IPC 消息类型 narrowing
daemon/src/kernel.ts 消除 null as unknown as ReflexScheduler
daemon/src/ipc.ts 改善 IPC handler 类型推断
daemon/src/sense-runtime.ts 类型化 node:sqlite / drizzle 返回值,用 type guard 替代 as 断言
store/src/log-store.ts 改善存储层类型断言

Ref

纯重构,无行为变更。Build 通过。

## What TypeScript 类型安全优化,消除 codebase 中的类型断言和 as 强制转换。 ## Why 减少运行时类型安全隐患,让编译器能捕获更多错误。 ## Changes | 文件 | 变更 | |------|------| | core/src/is-plain-record.ts | 新增 isPlainRecord() type guard | | core/src/config.ts | 用 isPlainRecord() 替代手动检查和 as 断言 | | cli/src/commands/start.ts | as any → as unknown as { fd: number }(FFI边界) | | cli/src/daemon-client.ts | 改善 IPC 消息类型 narrowing | | daemon/src/kernel.ts | 消除 null as unknown as ReflexScheduler | | daemon/src/ipc.ts | 改善 IPC handler 类型推断 | | daemon/src/sense-runtime.ts | 类型化 node:sqlite / drizzle 返回值,用 type guard 替代 as 断言 | | store/src/log-store.ts | 改善存储层类型断言 | ## Ref 纯重构,无行为变更。Build 通过。
xingyue added 1 commit 2026-04-24 12:08:29 +00:00
- Add isPlainRecord() type guard to eliminate 'as Record<string, unknown>' casts
- Replace 'as any' with properly typed assertions in start.ts
- Remove 'null as unknown as' pattern in kernel.ts
- Add type predicates for array narrowing (item is string)
- Improve IPC message type narrowing in daemon-client.ts and ipc.ts
- Type better-sqlite3 and drizzle return values properly

No runtime behavior changes.
xiaomo approved these changes 2026-04-24 12:09:35 +00:00
xiaomo left a comment
Owner

LGTM isPlainRecord() type guard 一招解决全局 as Record 问题,干净。亮点:ipc.ts parseParentMessage/parseWorkerMessage 从 raw as X 改为逐字段构造返回对象,彻底消除运行时类型不匹配风险。isSenseInfo/isWorkflowDefinitionShape 等 type guard 也很扎实。let scheduler!: ReflexScheduler 用 definite assignment 替代 null as unknown 是正确做法。

LGTM ✅ isPlainRecord() type guard 一招解决全局 as Record 问题,干净。亮点:ipc.ts parseParentMessage/parseWorkerMessage 从 raw as X 改为逐字段构造返回对象,彻底消除运行时类型不匹配风险。isSenseInfo/isWorkflowDefinitionShape 等 type guard 也很扎实。`let scheduler!: ReflexScheduler` 用 definite assignment 替代 null as unknown 是正确做法。
xiaomo merged commit 5b65afdc4b into main 2026-04-24 12:09:37 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
2 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#90