drizzle-team / drizzle-team/drizzle-orm

[BUG]: Incorrect type inference on relational query

Open
#968 12 comments 3 reactions 1 assignee Claimed by @Angelelz View on GitHub
bug docs docs/improvements priority
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### What version of `drizzle-orm` are you using?

0.27.2

### What version of `drizzle-kit` are you using?

0.19.12

### Describe the Bug

My prepared statement is correctly returning the data I would expect, but the type that is inferred does not match.

Prepared Statement
```
export const pGetTrainingSetWithExamples = db.query.trainingSets
.findFirst({
where: eq(trainingSets.publicId, placeholder("publicId")),
with: {
examples: true,
},
})
.prepare();
```

Returned data:

```
{
id: 1,
publicId: 'abcd',
userId: '1234',
name: 'Indicators',
description: 'Indicators',
stopSequence: null,
promptSeparator: null,
createdAt: 2023-08-02T06:53:30.000Z,
lastUpdated: 2023-08-02T06:53:30.000Z,
examples: [
{
id: 1,
prompt: "Hi",
completion: 'Hello',
flagged: null,
reviewed: null,
locked: null,
validFrom: null,
validTo: null,
trainingSetId: 1,
createdAt: 2023-08-02T08:05:49.000Z,
lastUpdated: 2023-08-02T08:05:49.000Z
}
]
}
```

I would expect `examples` to be on the type. You can see from the screenshot below that intellisense is not picking up on it.

image

### Expected behavior

The type to match the data

### Environment & setup

local

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.