drizzle-team / drizzle-team/drizzle-orm

[BUG]: $dynamic query example not working when passing T extends SelectedFields to select query

Open
#1,817 0 comments 0 reactions 0 assignees View on GitHub
bug docs docs/incorrect 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.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

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.