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

Returning method types #4881

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions test-tsd/transaction.test-d.ts
Expand Up @@ -25,6 +25,18 @@ const main = async () => {
.returning(['id', 'subject']);
}));

expectType<Pick<Article, "id" | "subject">[]>(await knexInstance.transaction((trx) => {
const articles: Article[] = [
{ id: 1, subject: 'Canterbury Tales' },
{ id: 2, subject: 'Moby Dick' },
{ id: 3, subject: 'Hamlet' },
];
return trx
.insert(articles)
.into<Article>('articles')
.returning(['id', trx.raw('subject')]);
}));

expectType<Article[]>(await knexInstance.transaction((trx) => {
return trx
.select('*')
Expand Down
6 changes: 3 additions & 3 deletions types/index.d.ts
Expand Up @@ -914,7 +914,7 @@ export declare namespace Knex {
options?: DMLOptions
): QueryBuilder<TRecord, TResult2>;
returning<TResult2 = SafePartial<TRecord>[]>(
column: string | readonly string[],
column: string | readonly (string | Raw)[] | Raw,
options?: DMLOptions
): QueryBuilder<TRecord, TResult2>;

Expand Down Expand Up @@ -1007,7 +1007,7 @@ export declare namespace Knex {
options?: DMLOptions
): QueryBuilder<TRecord, TResult2>;
delete<TResult2 = any>(
returning: string | readonly string[],
returning: string | readonly (string | Raw)[] | Raw,
options?: DMLOptions
): QueryBuilder<TRecord, TResult2>;
delete<TResult2 = number>(): QueryBuilder<TRecord, TResult2>;
Expand Down Expand Up @@ -1781,7 +1781,7 @@ export declare namespace Knex {
): BatchInsertBuilder<TRecord, TResult2>;
// if data with specific type passed, exclude this method
returning<TResult2 = SafePartial<TRecord>[]>(
column: unknown extends TRecord ? string | readonly string[] : never
column: unknown extends TRecord ? string | readonly (string | Raw)[] | Raw: never
): BatchInsertBuilder<TRecord, TResult2>;
}

Expand Down