缺失字段与已观察到的 null
样本 1
{
"id": 101,
"email": "ada@example.test"
}样本 2
{
"id": 102,
"email": null,
"phone": "555-0100"
}预期 TypeScript 草稿
export interface ApiUser {
id: number;
email: string | null;
phone?: string;
}初始选项: 根名称 ApiUser;开启可选推断;空数组默认 unknown[]。
核对结果: email 为 string 与 null 的联合类型,phone 为可选。关闭可选推断后 phone 必填,样本 1 不能作为完整 ApiUser 赋值。
键缺失与 null 值含义不同,均不能证明完整契约。