From 84d10599aa788c7eaa5f98e71afa0567c97f62c8 Mon Sep 17 00:00:00 2001 From: zackzeno Date: Mon, 17 Sep 2018 04:02:49 -0400 Subject: [PATCH] [lovefield] Replace Object with object (#28757) This is my first contribution, so I'm not sure if I missed something. I plan to make a more detailed edit in the future that replaces object with true generics, but it's not immediately obvious how to do that. Please fill in this template. - [x] Use a meaningful title for the pull request. Include the name of the package modified. - [x] Test the change in your own code. (Compile and run.) - [x] Add or edit tests to reflect the change. (Run with `npm test`.) - [x] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#make-a-pull-request). - [x] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes). - [x] Run `npm run lint package-name` (or `tsc` if no `tslint.json` is present). Select one of these and delete the others: If changing an existing definition: - [x] Provide a URL to documentation or source code which provides context for the suggested changes: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes - [x] Increase the version number in the header if appropriate. - [x] If you are making substantial changes, consider adding a `tslint.json` containing `{ "extends": "dtslint/dt.json" }`. --- types/lovefield/index.d.ts | 18 ++++++++++-------- types/lovefield/lovefield-tests.ts | 12 +++++++++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/types/lovefield/index.d.ts b/types/lovefield/index.d.ts index de02f3c914..bca0c708f1 100644 --- a/types/lovefield/index.d.ts +++ b/types/lovefield/index.d.ts @@ -1,7 +1,9 @@ // Type definitions for Lovefield 2.1 // Project: http://google.github.io/lovefield/ // Definitions by: freshp86 +// zackzeno // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 declare namespace lf { enum Order { ASC, DESC } @@ -59,10 +61,10 @@ declare namespace lf { } interface Transaction { - attach(query: query.Builder): Promise; + attach(query: query.Builder): Promise; begin(scope: schema.Table[]): Promise; commit(): Promise; - exec(queries: query.Builder[]): Promise; + exec(queries: query.Builder[]): Promise; rollback(): Promise; stats(): TransactionStats; } @@ -73,9 +75,9 @@ declare namespace lf { close(): void; createTransaction(type?: TransactionType): Transaction; delete(): query.Delete; - export(): Promise; + export(): Promise; getSchema(): schema.Database; - import(data: Object): Promise; + import(data: object): Promise; insertOrReplace(): query.Insert; insert(): query.Insert; observe(query: query.Select, callback: Function): void; @@ -87,7 +89,7 @@ declare namespace lf { namespace query { interface Builder { bind(...values: any[]): Builder; - exec(): Promise; + exec(): Promise; explain(): string; toSql(): string; } @@ -131,9 +133,9 @@ declare namespace lf { renameTableColumn( tableName: string, oldColumnName: string, newColumnName: string): Promise; - createRow(payload: Object): Row; + createRow(payload: object): Row; getVersion(): number; - dump(): Object[]; + dump(): object[]; } } // module raw @@ -166,7 +168,7 @@ declare namespace lf { interface ITable { as(name: string): Table; - createRow(value: Object): Row; + createRow(value: object): Row; getName(): string; } diff --git a/types/lovefield/lovefield-tests.ts b/types/lovefield/lovefield-tests.ts index fade4e6755..0c7203fbfc 100644 --- a/types/lovefield/lovefield-tests.ts +++ b/types/lovefield/lovefield-tests.ts @@ -1,4 +1,10 @@ import lf = require("lovefield"); +export interface IRow { + id: number; + description: string; + deadline: Date; + done: boolean; +} function main(): void { const schemaBuilder: lf.schema.Builder = lf.schema.create('todo', 1); @@ -28,11 +34,11 @@ function main(): void { }); return db.insertOrReplace().into(itemSchema).values([row]).exec(); }).then(() => { - const column = itemSchema['done']; - return todoDb.select().from(itemSchema).where(column.eq(false)).exec(); + const column = itemSchema.done; + return todoDb.select().from(itemSchema).where(column.eq(false)).exec() as Promise; }).then((results) => { results.forEach((row) => { - document.body.textContent = `${(row as any).description} before ${(row as any).deadline}`; + document.body.textContent = `${row.description} before ${row.deadline}`; }); return todoDb.delete().from(itemSchema);