function isRecord(value: unknown): value is Record { return typeof value === 'object' && value !== null && !Array.isArray(value); } function walk(node: unknown, visit: (obj: Record) => void): void { if (Array.isArray(node)) { for (const child of node) walk(child, visit); return; } if (!isRecord(node)) return; visit(node); for (const value of Object.values(node)) walk(value, visit); } type Person = { id: string }; function readPersons(list: Record): Person[] { if (!Array.isArray(list.persons)) return []; return list.persons .filter(isRecord) .map((p) => (typeof p.id === 'string' ? { id: p.id } : null)) .filter((p): p is Person => Boolean(p)); } /** * 在卡片 JSON 上应用投票:把 openId 写进 `vote_