Skip to content

Commit

Permalink
Returning method types (#4881)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierCavadenti committed Dec 7, 2021
1 parent d5e7e19 commit e4f4446
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
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

0 comments on commit e4f4446

Please sign in to comment.