Documentation
¶
Overview ¶
gen-ts — 从 idl/*.thrift 生成纯 TypeScript 类型声明(.d.ts)到 gen/ts/。
与 cmd/gen-openapi 同源同真相:同一批 service IDL、同一套字段序列化名规则 (serializedFieldName:优先 api.* 注解值,回退字段名),保证 gen/(Go 模型)、 openapi/openapi.json、gen/ts/(前端类型)三份产物对同一 IDL 恒一致; main_test.go 另以 openapi.json 的 schema 名单做跨产物对账,防两套字段名规则漂移。
产出(全部随仓提交,勿手改;CI --check 守卫):
gen/ts/<domain>.d.ts 每 go namespace 一个模块,纯 interface/type,零 runtime gen/ts/index.d.ts 桶出口:export type * as <domain> from './<domain>'
跨域同名类型(现网 BaseConfig/StorageConfig/EmptyReq)由命名空间隔离, 故 index 不做顶层 export *;消费方 `import type { share } from '@pigeonbox/contracts'` 后按 share.ShareDetail 取用。
类型映射:i*/double → number(JSON 反序列化本就是 number,现网值域(时间戳/ 字节数)远低于 2^53;未来出现大整数场景在消费侧转 bigint/string,勿在此全局改动); string/binary → string;list/set → T[];map → Record<string, V>(JSON object 键恒为字符串);struct/union/exception → interface;enum → 数字字面量联合; optional → ?:;typedef → type 别名。
用法:
go run ./cmd/gen-ts # 生成 gen/ts/ go run ./cmd/gen-ts --check # 只校验 gen/ts 与 IDL 同步(CI 用)