Commit 0950952
committed
fix(db): preserve null in coalesce() return type when no guaranteed non-null arg
The previous implementation used NonNullable<ExtractType<T>> on just the
first arg, stripping null from the return type unconditionally. This was
unsound because the runtime evaluator returns null when all args are null.
New behavior:
- Strip null only when at least one arg is statically guaranteed non-null
(does not include null | undefined in its type)
- Keep null in the result type when all args could be null/undefined
Examples:
coalesce(user.name, 'Unknown') → BasicExpression<string> (non-null literal fallback)
coalesce(user.department_id) → BasicExpression<number | null> (nullable only)
coalesce(user.department_id, 0) → BasicExpression<number> (0 is guaranteed non-null)
coalesce(user.department_id, dept?.id) → BasicExpression<number | null> (dept?.id can be undefined)
Added type tests for the nullable-only and guaranteed-non-null cases.
Addresses review feedback from samwillis.1 parent 34eb4bf commit 0950952
File tree
2 files changed
+41
-6
lines changed- packages/db
- src/query/builder
- tests/query/builder
2 files changed
+41
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
292 | 315 | | |
293 | 316 | | |
294 | | - | |
295 | | - | |
| 317 | + | |
| 318 | + | |
296 | 319 | | |
297 | 320 | | |
298 | 321 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
155 | 167 | | |
156 | 168 | | |
157 | 169 | | |
| |||
0 commit comments