drizzle-team / drizzle-team/drizzle-orm

How to deal join field possibly null type? Typescript errors even after checks

Open
#4,762 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

Hi,

I have an issue with left join return data.
I am validating that it's not null, but still type check fail unless I do massive deconstruct.

```ts
if (post.author) {
return post; // <- Error, type Author | null is not assignable to type Author
}
```
I created a typescript playground to illustrate it better
https://www.typescriptlang.org/play/?target=10&pretty=false#code/JYOwLgpgTgZghgYwgAgIIFcwAsD2VkDeAUMqcsACYBcyAzmFKAOYDcRAvkUaJLIigAUc9QiTKUa9RiFZjScTLig0M2PG07dw0eEmRD6AdWDYAcugA2F0WXLU6DZm1sK1ytIrzIAPshCWLDS4EHBARAFtgAA8ICgARODA4ZABeZABtORtbcXsAcgBGACYAZjyAGiyXT3d-K0rbdgayYhzcmjzSgBYKqrJXJRpWtpyJZEK8vtImrM4AXTYiGHQQBDBgUOQmCDADMAAhAE8ASQoACjGpZgBKGj2fPwDs0hCwsGQoCFpU5EiY+MScAAdDBQOczp8QlAKNdUgA+D4QKEUIGUVIpNKUWFwb57YxmALOcQwZBnACEn1osOGbU+YHQUBAjysROmXFswBJEK+QIGeGpU0R9MZiNorJyAHoJcgACpYFAhCgoABGEAsOAA7sgNcArNq8ABrIGCqVChlMmmS6W2IG2ynNNqm6puGiU3k1E3SziNLhZOnm5mBDhEIA

Is there a workaround it? Or is there maybe a way for Drizzle to disable the `| null` thing? as this thing is referenceKey that cannot be null.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.