Skip to content

Commit

Permalink
Added promisable and better types (#5222)
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicVonk committed Jun 14, 2022
1 parent 0918bf9 commit f80ec1c
Show file tree
Hide file tree
Showing 2 changed files with 816 additions and 414 deletions.
8 changes: 4 additions & 4 deletions test-tsd/querybuilder.test-d.ts
Expand Up @@ -11,17 +11,17 @@ const knexInstance = knex(clientConfig);
declare module '../types' {
namespace Knex {
interface QueryBuilder {
customSelect<TRecord, TResult>(
customSelect<TRecord extends {}, TResult> (
value: number
): Knex.QueryBuilder<TRecord, TResult>;
): Promise<Knex.QueryBuilder<TRecord, TResult>>;
}
}
}

knex.QueryBuilder.extend('customSelect', function (value: number) {
return this.select(this.client.raw(`${value} as value`));
return new Promise((r) => r(this.select(this.client.raw(`${value} as value`))));
});

const main = async () => {
expectType<number[]>(await knexInstance('users').customSelect<any, number[]>(42));
expectType<number[]>(await (await knexInstance('users').customSelect<any, number[]>(42)));
};

0 comments on commit f80ec1c

Please sign in to comment.