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

QueryHelperResult doesn't accept helper with optional argument #319

Open
IlyaSemenov opened this issue Jul 8, 2024 · 0 comments
Open

QueryHelperResult doesn't accept helper with optional argument #319

IlyaSemenov opened this issue Jul 8, 2024 · 0 comments

Comments

@IlyaSemenov
Copy link
Contributor

QueryHelperResult doesn't accept helper with optional argument:

import { type QueryHelperResult, createBaseTable, orchidORM } from "orchid-orm"

const BaseTable = createBaseTable()

class PostTable extends BaseTable {
  readonly table = "post"

  columns = this.setColumns(t => ({
    id: t.identity().primaryKey(),
    text: t.text(),
  }))
}

const db = orchidORM({}, { post: PostTable })

const selectPost = db.post.makeHelper((q, searchTerm?: string) =>
  q.where(q => searchTerm ? q.whereSql`text like ${`%${searchTerm}%`}` : q),
)

// Type 'unknown' is not assignable to type 'string | undefined'.
export type Post = Awaited<QueryHelperResult<typeof selectPost>>[0]
image

Interestingly though, this works:

const selectPost = db.post.makeHelper((q, searchTerm = "") =>
  q.where(q => searchTerm ? q.whereSql`text like ${`%${searchTerm}%`}` : q),
)

// No type errors
export type Post = Awaited<QueryHelperResult<typeof selectPost>>[0]
  • orchid-orm 1.32.13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant