33declare module 'alasql' {
44 import * as xlsx from 'xlsx' ;
55
6- interface AlaSQLCallback {
7- ( data ?: any , err ?: Error ) : void ;
6+ // Callback with error-first convention and optional data
7+ interface AlaSQLCallback < T = unknown > {
8+ ( err : Error | null , data ?: T ) : void ;
89 }
910
1011 interface AlaSQLOptions {
@@ -15,7 +16,7 @@ declare module 'alasql' {
1516 casesensitive : boolean ; // table and column names are case sensitive and converted to lower-case
1617 logtarget : string ; // target for log. Values: 'console', 'output', 'id' of html tag
1718 logprompt : boolean ; // print SQL at log
18- modifier : any ; // values: RECORDSET, VALUE, ROW, COLUMN, MATRIX, TEXTSTRING, INDEX
19+ modifier ?: ' RECORDSET' | ' VALUE' | ' ROW' | ' COLUMN' | ' MATRIX' | ' TEXTSTRING' | ' INDEX' ;
1920 columnlookup : number ; // how many rows to lookup to define columns
2021 autovertex : boolean ; // create vertex if not found
2122 usedbo : boolean ; // use dbo as current database (for partial T-SQL comaptibility)
@@ -30,35 +31,22 @@ declare module 'alasql' {
3031 oracle : boolean ;
3132 sqlite : boolean ;
3233 orientdb : boolean ;
33- excel : any ;
34+ excel ?: xlsx . WorkBook ; // now typed
3435 }
3536
3637 // compiled Statement
3738 interface AlaSQLStatement {
38- ( params ?: any , cb ?: AlaSQLCallback , scope ?: any ) : any ;
39+ < T = unknown > ( params ?: Record < string , unknown > , cb ?: AlaSQLCallback < T > , scope ?: unknown ) : T ;
3940 }
4041
4142 // abstract Syntax Tree
4243 interface AlaSQLAST {
4344 compile ( databaseid : string ) : AlaSQLStatement ;
4445 }
4546
46- // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/es6-promise/es6-promise.d.ts
47- interface Thenable < T > {
48- then < U > (
49- onFulfilled ?: ( value : T ) => U | Thenable < U > ,
50- onRejected ?: ( error : any ) => U | Thenable < U >
51- ) : Thenable < U > ;
52- then < U > (
53- onFulfilled ?: ( value : T ) => U | Thenable < U > ,
54- onRejected ?: ( error : any ) => void
55- ) : Thenable < U > ;
56- catch < U > ( onRejected ?: ( error : any ) => U | Thenable < U > ) : Thenable < U > ;
57- }
58-
5947 // see https://github.com/alasql/alasql/wiki/User%20Defined%20Functions
6048 interface userDefinedFunction {
61- ( ...x : any [ ] ) : any ;
49+ ( ...x : unknown [ ] ) : unknown ;
6250 }
6351
6452 interface userDefinedFunctionLookUp {
@@ -67,15 +55,21 @@ declare module 'alasql' {
6755
6856 // see https://github.com/alasql/alasql/wiki/User%20Defined%20Functions
6957 interface userAggregator {
70- ( value : any , accumulator : any , stage : number ) : any ;
58+ ( value : unknown , accumulator : unknown , stage : number ) : unknown ;
7159 }
7260
7361 interface userAggregatorLookUp {
7462 [ x : string ] : userAggregator ;
7563 }
7664
7765 interface userFromFunction {
78- ( dataReference : any , options : any , callback : any , index : any , query : any ) : any ;
66+ (
67+ dataReference : unknown ,
68+ options : unknown ,
69+ callback : ( res : unknown ) => void ,
70+ index : unknown ,
71+ query : unknown
72+ ) : void ;
7973 }
8074
8175 interface userFromFunctionLookUp {
@@ -117,7 +111,7 @@ declare module 'alasql' {
117111 * @type {any[] }
118112 * @memberof table
119113 */
120- data : any [ ] ;
114+ data : unknown [ ] ;
121115 }
122116
123117 /**
@@ -142,25 +136,31 @@ declare module 'alasql' {
142136 new ( databaseid ?: string ) : Database ;
143137 databaseid : string ;
144138 dbversion : number ;
145- tables : { [ key : string ] : any } ;
146- views : { [ key : string ] : any } ;
147- triggers : { [ key : string ] : any } ;
148- indices : { [ key : string ] : any } ;
149- objects : { [ key : string ] : any } ;
139+ tables : { [ key : string ] : unknown } ;
140+ views : { [ key : string ] : unknown } ;
141+ triggers : { [ key : string ] : unknown } ;
142+ indices : { [ key : string ] : unknown } ;
143+ objects : { [ key : string ] : unknown } ;
150144 counter : number ;
151- sqlCache : { [ key : string ] : any } ;
145+ sqlCache : { [ key : string ] : unknown } ;
152146 sqlCacheSize : number ;
153- astCache : { [ key : string ] : any } ;
154- resetSqlCache : ( ) => void ;
155- exec : ( sql : string , params ?: object , cb ?: Function ) => any ;
156- autoval : ( tablename : string , colname : string , getNext : boolean ) => any ;
147+ astCache : { [ key : string ] : unknown } ;
148+ resetSqlCache ( ) : void ;
149+ exec < T = unknown > ( sql : string , params ?: Record < string , unknown > , cb ?: AlaSQLCallback < T > ) : T ;
150+ autoval ( tablename : string , colname : string , getNext : boolean ) : unknown ;
157151 }
152+
158153 interface AlaSQL {
159154 options : AlaSQLOptions ;
160155 error : Error ;
161- ( sql : any , params ?: any , cb ?: AlaSQLCallback , scope ?: any ) : any ;
162- parse ( sql : any ) : AlaSQLAST ;
163- promise ( sql : any , params ?: any ) : Thenable < any > ;
156+ < T = unknown > (
157+ sql : string ,
158+ params ?: Record < string , unknown > ,
159+ cb ?: AlaSQLCallback < T > ,
160+ scope ?: unknown
161+ ) : T ;
162+ parse ( sql : string ) : AlaSQLAST ;
163+ promise < T = unknown > ( sql : string , params ?: Record < string , unknown > ) : Promise < T > ;
164164 fn : userDefinedFunctionLookUp ;
165165 from : userFromFunctionLookUp ;
166166 aggr : userAggregatorLookUp ;
@@ -200,7 +200,7 @@ declare module 'alasql' {
200200
201201 /**
202202 * Array of the tables in the default database (called alasql). If
203- * the database is changes via a USE statement or the use method, this
203+ * the database is changed via a USE statement or the use method, this
204204 * becomes the tables in the new database.
205205 *
206206 * @type {tableLookUp }
0 commit comments