Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE]: Nullable type inference with .mapWith() #571

Open
Tracked by #3649
Nikola-Milovic opened this issue May 11, 2023 · 0 comments
Open
Tracked by #3649

[FEATURE]: Nullable type inference with .mapWith() #571

Nikola-Milovic opened this issue May 11, 2023 · 0 comments
Labels
bug Something isn't working priority Will be worked on next qb/crud

Comments

@Nikola-Milovic
Copy link

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:

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)

Environment

Drizzle version: 0.25.4
TypeScript version: 5.0.3
Node.js version: 18

@Nikola-Milovic Nikola-Milovic added the enhancement New feature or request label May 11, 2023
@L-Mario564 L-Mario564 added bug Something isn't working priority Will be worked on next qb/crud and removed enhancement New feature or request labels Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority Will be worked on next qb/crud
Projects
None yet
Development

No branches or pull requests

2 participants