Skip to content

Commit

Permalink
Include undefined in Single row results (#3231)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorefnon authored and kibertoad committed May 30, 2019
1 parent 1fe5ee0 commit bd63288
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion types/index.d.ts
Expand Up @@ -216,7 +216,7 @@ declare namespace DeferredKeySelection {

// Resolution logic lifted over arrays of deferred selections
type Resolve<TSelection> = TSelection extends DeferredKeySelection.Any
? ResolveOne<TSelection>
? (ResolveOne<TSelection> | undefined)
: TSelection extends DeferredKeySelection.Any[]
? ResolveOne<TSelection[0]>[]
: TSelection;
Expand Down
22 changes: 11 additions & 11 deletions types/test.ts
Expand Up @@ -100,22 +100,22 @@ const main = async () => {
// $ExpectType any
await knex('users').first(knex.ref('id').as('identifier'));

// $ExpectType Pick<User, "id">
// $ExpectType Pick<User, "id"> | undefined
await knex<User>('users').first('id');

// $ExpectType Pick<User, "id" | "name">
// $ExpectType Pick<User, "id" | "name"> | undefined
await knex<User>('users').first('id', 'name');

// $ExpectType { identifier: number; }
// $ExpectType { identifier: number; } | undefined
await knex<User>('users').first(knex.ref('id').as('identifier'));

// $ExpectType Pick<User, "id">
// $ExpectType Pick<User, "id"> | undefined
await knex.first('id').from<User>('users');

// $ExpectType Pick<User, "id" | "name">
// $ExpectType Pick<User, "id" | "name"> | undefined
await knex.first('id', 'name').from<User>('users');

// $ExpectType { identifier: number; }
// $ExpectType { identifier: number; } | undefined
await knex.first(knex.ref('id').as('identifier')).from<User>('users');

// $ExpectType Pick<User, "id">[]
Expand Down Expand Up @@ -207,7 +207,7 @@ const main = async () => {
// $ExpectType { id: number; age: any; }[]
await knex<User>('users').select(knex.ref('id'), {age: 'users.age'});

// $ExpectType { id: number; age: any; }
// $ExpectType { id: number; age: any; } | undefined
await knex<User>('users').select(knex.ref('id'), {age: 'users.age'}).first();

// $ExpectType { identifier: number; username: string; }[]
Expand Down Expand Up @@ -248,7 +248,7 @@ const main = async () => {
// $ExpectType Pick<User, "id" | "age">[]
await knex<User>('users').select(['id', 'age']);

// $ExpectType Pick<User, "id" | "age">
// $ExpectType Pick<User, "id" | "age"> | undefined
await knex<User>('users')
.select(['id', 'age'])
.first();
Expand Down Expand Up @@ -400,7 +400,7 @@ const main = async () => {
.join('departments', 'departments.id', '=', 'users.department_id')
.orderByRaw('name DESC');

// $ExpectType User
// $ExpectType User | undefined
await knex<User>('users')
.where({ id: 10 })
.first();
Expand All @@ -414,7 +414,7 @@ const main = async () => {
// $ExpectType User[]
await knex.where({ id: 10 }).from<User>('users');

// $ExpectType User
// $ExpectType User | undefined
await knex
.where({ id: 10 })
.from<User>('users')
Expand Down Expand Up @@ -516,7 +516,7 @@ const main = async () => {
this.where('id', '>', 10);
});

// $ExpectType User
// $ExpectType User | undefined
await knex<User>('users')
.where((builder) =>
builder.whereIn('id', [1, 11, 15]).whereNotIn('id', [17, 19])
Expand Down

0 comments on commit bd63288

Please sign in to comment.