From 18fad79175c394c6adf19600a37ab4e12affb2eb Mon Sep 17 00:00:00 2001 From: Ryan Smith <0ryansmith1994@gmail.com> Date: Wed, 30 Mar 2016 15:05:16 +0100 Subject: [PATCH 1/5] Fixes for ES6. --- knex/knex.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/knex/knex.d.ts b/knex/knex.d.ts index 6f28a2f796..52740662c8 100644 --- a/knex/knex.d.ts +++ b/knex/knex.d.ts @@ -3,12 +3,12 @@ // Definitions by: Qubo // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// +// /// declare module "knex" { - import Promise = require("bluebird"); - import events = require("events"); + // import Promise = require("bluebird"); + import * as events from "events"; type Callback = Function; type Client = Function; From 7fb76f6e39135b7a3e7c3c384a9e28202b91a514 Mon Sep 17 00:00:00 2001 From: Ryan Smith <0ryansmith1994@gmail.com> Date: Wed, 30 Mar 2016 18:11:16 +0100 Subject: [PATCH 2/5] Fixes most TS2339 and all TS7006 errors. --- knex/knex-tests.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/knex/knex-tests.ts b/knex/knex-tests.ts index 4078522df2..2113be68d7 100644 --- a/knex/knex-tests.ts +++ b/knex/knex-tests.ts @@ -329,11 +329,11 @@ knex.transaction(function(trx) { .insert({name: 'Old Books'}, 'id') .into('catalogues') .then(function(ids) { - return Promise.map(books, function(book) { + return Promise.all(books.map(function (book: any) { book.catalogue_id = ids[0]; // Some validation could take place here. return trx.insert(info).into('books'); - }); + })); }); }) .then(function(inserts) { @@ -359,13 +359,13 @@ knex.transaction(function(trx) { .into('catalogues') .transacting(trx) .then(function(ids) { - return Promise.map(books, function(book) { + return Promise.all(books.map(function(book: any) { book.catalogue_id = ids[0]; // Some validation could take place here. return knex.insert(info).into('books').transacting(trx); - }); + })); }) .then(trx.commit) .catch(trx.rollback); @@ -497,9 +497,9 @@ query.then(function(x: any) { knex.select('name').from('users').limit(10).map(function(row: any) { return row.name; -}).then(function(names) { +}).then(function(names: string) { console.log(names); -}).catch(function(e) { +}).catch(function(e: Error) { console.error(e); }); @@ -507,9 +507,9 @@ knex.select('name').from('users').limit(10).reduce(function(memo: any, row: any) memo.names.push(row.name); memo.count++; return memo; -}, {count: 0, names: []}).then(function(obj) { +}, {count: 0, names: []}).then(function(obj: any) { console.log(obj); -}).catch(function(e) { +}).catch(function(e: Error) { console.error(e); }); From 905ee7e6f5a1971e3f8aef16ee789f4600ca5e51 Mon Sep 17 00:00:00 2001 From: Ryan Smith <0ryansmith1994@gmail.com> Date: Wed, 30 Mar 2016 18:18:16 +0100 Subject: [PATCH 3/5] Attempts to fix more TS2339 errors. ``` knex/knex-tests.ts(498,45): error TS2339: Property 'map' does not exist on type 'QueryBuilder'. knex/knex-tests.ts(506,45): error TS2339: Property 'reduce' does not exist on type 'QueryBuilder'. ``` https://travis-ci.org/DefinitelyTyped/DefinitelyTyped/builds/119590526 --- knex/knex-tests.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/knex/knex-tests.ts b/knex/knex-tests.ts index 2113be68d7..c0483c5d97 100644 --- a/knex/knex-tests.ts +++ b/knex/knex-tests.ts @@ -495,19 +495,23 @@ query.then(function(x: any) { return x; }); -knex.select('name').from('users').limit(10).map(function(row: any) { - return row.name; +knex.select('name').from('users').limit(10).then(function (rows: any[]) { + return rows.map(function (row: string) { + return row.name; + }); }).then(function(names: string) { console.log(names); }).catch(function(e: Error) { console.error(e); }); -knex.select('name').from('users').limit(10).reduce(function(memo: any, row: any) { - memo.names.push(row.name); - memo.count++; - return memo; -}, {count: 0, names: []}).then(function(obj: any) { +knex.select('name').from('users').limit(10).then(function (rows: any[]) { + return rows.reduce(function(memo: any, row: any) { + memo.names.push(row.name); + memo.count++; + return memo; + }, {count: 0, names: []}) +}).then(function(obj: any) { console.log(obj); }).catch(function(e: Error) { console.error(e); From ff6d2d2b904d8b97b478385632f4b7841ecf2df3 Mon Sep 17 00:00:00 2001 From: Ryan Smith <0ryansmith1994@gmail.com> Date: Wed, 30 Mar 2016 18:22:39 +0100 Subject: [PATCH 4/5] Attempts to fix new errors. ``` knex/knex-tests.ts(500,16): error TS2339: Property 'name' does not exist on type 'string'. knex/knex-tests.ts(502,9): error TS2345: Argument of type '(names: string) => void' is not assignable to parameter of type '(value: any[]) => void | PromiseLike'. Types of parameters 'names' and 'value' are incompatible. Type 'string' is not assignable to type 'any[]'. ``` https://travis-ci.org/DefinitelyTyped/DefinitelyTyped/builds/119592117 --- knex/knex-tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/knex/knex-tests.ts b/knex/knex-tests.ts index c0483c5d97..cd67a08736 100644 --- a/knex/knex-tests.ts +++ b/knex/knex-tests.ts @@ -495,8 +495,8 @@ query.then(function(x: any) { return x; }); -knex.select('name').from('users').limit(10).then(function (rows: any[]) { - return rows.map(function (row: string) { +knex.select('name').from('users').limit(10).then(function (rows: any[]): string[] { + return rows.map(function (row: any): string { return row.name; }); }).then(function(names: string) { From 84ae09b62434e524ea043498fb2f7ea4f9744353 Mon Sep 17 00:00:00 2001 From: Ryan Smith <0ryansmith1994@gmail.com> Date: Wed, 30 Mar 2016 18:29:30 +0100 Subject: [PATCH 5/5] Attempts to fix remaining errors. ``` knex/knex-tests.ts(502,9): error TS2345: Argument of type '(names: string) => void' is not assignable to parameter of type '(value: string[]) => void | PromiseLike'. Types of parameters 'names' and 'value' are incompatible. Type 'string' is not assignable to type 'string[]'. knex/knex-tests.ts(522,4): error TS2339: Property 'bind' does not exist on type 'QueryBuilder'. knex/knex-tests.ts(533,35): error TS2339: Property 'return' does not exist on type 'QueryBuilder'. ``` https://travis-ci.org/DefinitelyTyped/DefinitelyTyped/builds/119593429 --- knex/knex-tests.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/knex/knex-tests.ts b/knex/knex-tests.ts index cd67a08736..e983ec1084 100644 --- a/knex/knex-tests.ts +++ b/knex/knex-tests.ts @@ -499,7 +499,7 @@ knex.select('name').from('users').limit(10).then(function (rows: any[]): string[ return rows.map(function (row: any): string { return row.name; }); -}).then(function(names: string) { +}).then(function(names: string[]) { console.log(names); }).catch(function(e: Error) { console.error(e); @@ -519,19 +519,16 @@ knex.select('name').from('users').limit(10).then(function (rows: any[]) { knex.select('name').from('users') .limit(10) - .bind(console) - .then(console.log) - .catch(console.error); + .then(console.log.bind(console)) + .catch(console.error.bind(console)); var values: any[]; -// Without return: + knex.insert(values).into('users') .then(function() { return {inserted: true}; }); -knex.insert(values).into('users').return({inserted: true}); - knex.select('name').from('users') .where('id', '>', 20) .andWhere('id', '<', 200)