Complete worked example
typescript
type User = { id: string };
function adapt(value: unknown): User | undefined {
return typeof value === "object" && value !== null && "id" in value && typeof value.id === "string"
? { id: value.id } : undefined;
}- Reasoning
- The adapter establishes a trusted local shape instead of asserting that external output already matches it.