mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 20:21:46 +00:00
add variable arg function type inference, tests (#32390)
This commit is contained in:
committed by
Pranav Senthilnathan
parent
5578dc104f
commit
739ed3b1cf
@@ -69,3 +69,12 @@ trans.default('name');
|
||||
trans.deferred('name');
|
||||
trans.immediate('name');
|
||||
trans.exclusive('name');
|
||||
|
||||
const transTyped = db.transaction((param: number) => stmt.all(param));
|
||||
transTyped(1);
|
||||
trans.default(1);
|
||||
trans.deferred(1);
|
||||
trans.immediate(1);
|
||||
trans.exclusive(1);
|
||||
// $ExpectError
|
||||
transTyped('name');
|
||||
|
||||
Vendored
+15
-8
@@ -4,10 +4,17 @@
|
||||
// Mathew Rumsey <https://github.com/matrumz>
|
||||
// Santiago Aguilar <https://github.com/sant123>
|
||||
// Alessandro Vergani <https://github.com/loghorn>
|
||||
// Andrew Kaiser <https://github.com/andykais>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
import Integer = require("integer");
|
||||
|
||||
type VariableArgFunction = (...params: any[]) => any;
|
||||
type ArgumentTypes<F extends VariableArgFunction> = F extends (...args: infer A) => any
|
||||
? A
|
||||
: never;
|
||||
|
||||
declare namespace BetterSqlite3 {
|
||||
interface Statement {
|
||||
database: Database;
|
||||
@@ -34,12 +41,12 @@ declare namespace BetterSqlite3 {
|
||||
type: string | null;
|
||||
}
|
||||
|
||||
interface Transaction {
|
||||
(...params: any[]): any;
|
||||
default(...params: any[]): any;
|
||||
deferred(...params: any[]): any;
|
||||
immediate(...params: any[]): any;
|
||||
exclusive(...params: any[]): any;
|
||||
interface Transaction<F extends VariableArgFunction> {
|
||||
(...params: ArgumentTypes<F>): any;
|
||||
default(...params: ArgumentTypes<F>): any;
|
||||
deferred(...params: ArgumentTypes<F>): any;
|
||||
immediate(...params: ArgumentTypes<F>): any;
|
||||
exclusive(...params: ArgumentTypes<F>): any;
|
||||
}
|
||||
|
||||
interface Database {
|
||||
@@ -50,7 +57,7 @@ declare namespace BetterSqlite3 {
|
||||
inTransaction: boolean;
|
||||
|
||||
prepare(source: string): Statement;
|
||||
transaction(fn: (...params: any[]) => any): Transaction;
|
||||
transaction<F extends VariableArgFunction>(fn: F): Transaction<F>;
|
||||
exec(source: string): this;
|
||||
pragma(source: string, options?: Database.PragmaOptions): any;
|
||||
checkpoint(databaseName?: string): this;
|
||||
@@ -113,7 +120,7 @@ declare namespace Database {
|
||||
type SqliteError = typeof SqliteError;
|
||||
type Statement = BetterSqlite3.Statement;
|
||||
type ColumnDefinition = BetterSqlite3.ColumnDefinition;
|
||||
type Transaction = BetterSqlite3.Transaction;
|
||||
type Transaction = BetterSqlite3.Transaction<VariableArgFunction>;
|
||||
type Database = BetterSqlite3.Database;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user