question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failing types on "returning" methods

See original GitHub issue

I recently updated to the latest version of knex and I faced what I think is one of the breaking changes from the release notes:

Changed data structure from RETURNING operation to be consistent with SELECT;

const ids =  await knex.from("table").where(...).update({...}, "id");

used to return a string[] but now returns a {id: string}[], fair enough.

However some of the overloads still reflect the previous behavior. I managed to fix it with patch-package with the following diff but I’m not 100% this is the correct solution.

Am I on the right track?

diff --git a/node_modules/knex/types/index.d.ts b/node_modules/knex/types/index.d.ts
index d9bf6e5..b50c579 100644
--- a/node_modules/knex/types/index.d.ts
+++ b/node_modules/knex/types/index.d.ts
@@ -692,7 +692,7 @@ export declare namespace Knex {
     ): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
     insert<
       TKey extends StrKey<ResolveTableType<TRecord>>,
-      TResult2 = DeferredIndex.Augment<
+      TResult2 = DeferredKeySelection.Augment<
         UnwrapArrayMember<TResult>,
         ResolveTableType<TRecord>,
         TKey
@@ -720,7 +720,7 @@ export declare namespace Knex {
     ): QueryBuilder<TRecord, TResult2>;
     insert<
       TKey extends string,
-      TResult2 = DeferredIndex.Augment<
+      TResult2 = DeferredKeySelection.Augment<
         UnwrapArrayMember<TResult>,
         TRecord,
         TKey
@@ -828,7 +828,7 @@ export declare namespace Knex {
     update<
       K1 extends StrKey<ResolveTableType<TRecord, 'update'>>,
       K2 extends StrKey<ResolveTableType<TRecord>>,
-      TResult2 = DeferredIndex.Augment<
+      TResult2 = DeferredKeySelection.Augment<
         UnwrapArrayMember<TResult>,
         ResolveTableType<TRecord>,
         K2
@@ -870,7 +870,7 @@ export declare namespace Knex {
     ): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
     update<
       TKey extends StrKey<ResolveTableType<TRecord>>,
-      TResult2 = DeferredIndex.Augment<
+      TResult2 = DeferredKeySelection.Augment<
         UnwrapArrayMember<TResult>,
         ResolveTableType<TRecord>,
         TKey
@@ -925,7 +925,7 @@ export declare namespace Knex {
     returning(column: '*', options?: DMLOptions): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
     returning<
       TKey extends StrKey<ResolveTableType<TRecord>>,
-      TResult2 = DeferredIndex.Augment<
+      TResult2 = DeferredKeySelection.Augment<
         UnwrapArrayMember<TResult>,
         ResolveTableType<TRecord>,
         TKey

This issue body was partially generated by patch-package.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kibertoadcommented, Mar 13, 2022

Released in 1.0.4

0reactions
santialbocommented, Feb 21, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Return type method "Return value of the method is never used ...
I have to create a return type method takes String array as an argument and returns to int. So my method works completely...
Read more >
Is it a bad idea to return different data types from a single ...
In a statically typed language I get why this is a bad idea. If every method returned Object (the common parent all classes...
Read more >
Returning a Value from a Method (The Java™ Tutorials ...
The data type of the return value must match the method's declared return type; you can't return an integer value from a method...
Read more >
return keyword in Java - GeeksforGeeks
In Java, return is a reserved keyword i.e, we can't use it as an identifier. It is used to exit from a method,...
Read more >
Async return types (C#) - Microsoft Learn
Learn about the return types that async methods can have in C# ... Such unhandled exceptions are likely to cause your application to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found