| 28 | * synthesized. |
| 29 | */ |
| 30 | export function transformNullsToUndefined<T>(obj: T): T { |
| 31 | if (obj === null) { |
| 32 | return undefined as T |
| 33 | } |
| 34 | |
| 35 | if (typeof obj !== 'object') { |
| 36 | return obj |
| 37 | } |
| 38 | |
| 39 | if (Array.isArray(obj)) { |
| 40 | return obj.map((item) => transformNullsToUndefined(item)) as T |
| 41 | } |
| 42 | |
| 43 | const result: Record<string, unknown> = {} |
| 44 | for (const [key, value] of Object.entries(obj as Record<string, unknown>)) { |
| 45 | if (value === null) { |
| 46 | continue |
| 47 | } |
| 48 | result[key] = transformNullsToUndefined(value) |
| 49 | } |
| 50 | return result as T |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Records exactly where strict-mode null-widening synthesized a `null`, so |