drizzle-team / drizzle-team/drizzle-orm
[BUG]: $dynamic query example not working when passing T extends SelectedFields to select query
- 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.29.3
### What version of `drizzle-kit` are you using?
0.20.13
### Describe the Bug
That is the example in the docs for a dynamic query:
```typescript
function withFriends(qb: T) {
return qb.leftJoin(friends, eq(friends.userId, users.id));
}
let query = db.select().from(users).where(eq(users.id, 1)).$dynamic();
query = withFriends(query);
```
However, if I pass a projection to the select query, typescript complain:
```typescript
import { PgSelect, SelectedFields } from 'drizzle-orm/pg-core'
function withFriends(qb: T) {
return qb.leftJoin(friends, eq(friends.userId, users.id));
}
function selectWithProjection; ... 10 more ...; createdAt: PgColumn<...>; ...' is not assignable to parameter of type 'PgSelect'.
The types of '_.dynamic' are incompatible between these types.
Type 'boolean' is not assignable to type 'true'.ts(2345)`
### Expected behavior
dynamic query should work when passing `SelectedFields` to `select()`
### Environment & setup
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.