You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using .mapWith(), nullable type inference is not being properly handled. Without the .mapWith(), the type is inferred correctly, but when it's mapped, the type is always non-nullable. This seems to be a niche situation, but it would be helpful to address this edge case.
Steps to reproduce
Here's the code snippet that demonstrates the issue:
someNewField: sql<Type | null>`CASE WHEN some_field IS NOT NULL THEN some_field END`.mapWith(table.someField),
Type (property) destination: SQL<Type>
But if the .mapWith() is removed, it is correctly inferred to:
(property) destination: SQL<Type | null>
Expected behavior
The nullable type should be inferred correctly when using .mapWith()
As per @dankochetov solution, there is a workaround
Workaround
A custom mapper function can be used as a temporary solution:
function mapper(value: any): Type | null {
return table.someField.mapFromDriverValue(value);
}
sql<Type>``.mapWith(mapper)
Describe want to want
Description
When using
.mapWith()
, nullable type inference is not being properly handled. Without the.mapWith()
, the type is inferred correctly, but when it's mapped, the type is always non-nullable. This seems to be a niche situation, but it would be helpful to address this edge case.Steps to reproduce
Here's the code snippet that demonstrates the issue:
Type (property) destination: SQL<Type>
But if the
.mapWith()
is removed, it is correctly inferred to:(property) destination: SQL<Type | null>
Expected behavior
The nullable type should be inferred correctly when using
.mapWith()
As per @dankochetov solution, there is a workaround
Workaround
A custom mapper function can be used as a temporary solution:
Environment
Drizzle version:
0.25.4
TypeScript version:
5.0.3
Node.js version:
18
The text was updated successfully, but these errors were encountered: