angularjs - 在 'Argument of type '类型中,如何解决}' is not assignable to parameter of type ' {]'. [ng] Property ' any [ '{}' length'丢失了。

标签 angularjs typescript sqlite ionic-framework error-handling

我将在本教程的帮助下使用条形码扫描仪和SQLite构建Ionic库存管理应用程序:https://www.techiediaries.com/ionic-cordova-sqlite-barcode-scanner-product-inventory-manager/

当我添加以下代码时:

async createTables(){
    try {
        await this.database.executeSql(this.familyTable, {});
        await this.database.executeSql(this.locationTable,{});
        await this.database.executeSql(this.productTable,{});
        await this.database.executeSql(this.transactionTable,{});
    }catch(e){
        console.log("Error !");
    }
}

...到data-service.service.ts我收到此错误:

ERROR in src/app/data-service.service.ts(54,64): error TS2345: Argument of type '{}' is not assignable to parameter of type 'any[]'. [ng] Property 'length' is missing in type '{}'. [ng] src/app/data-service.service.ts(55,65): error TS2345: Argument of type '{}' is not assignable to parameter of type 'any[]'. [ng] Property 'length' is missing in type '{}'. [ng] src/app/data-service.service.ts(56,64): error TS2345: Argument of type '{}' is not assignable to parameter of type 'any[]'. [ng] Property 'length' is missing in type '{}'. [ng] src/app/data-service.service.ts(57,68): error TS2345: Argument of type '{}' is not assignable to parameter of type 'any[]'. [ng] Property 'length' is missing in type '{}'.



这是整个data-service.service.ts代码:
import { Injectable } from '@angular/core';

import 'rxjs/add/operator/map';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite/ngx';



@Injectable({
  providedIn: 'root'
})
export class DataServiceService {
  public database: SQLiteObject;

  productTable : string = `CREATE TABLE IF NOT EXISTS  products (
    id INTEGER PRIMARY KEY,
    sku TEXT,
    barcode TEXT,
    title TEXT NOT NULL,
    description TEXT,
    quantity REAL,
    unit VARCHAR,
    unitPrice REAL,
    minQuantity INTEGER,
    familly_id INTEGER,
    location_id INTEGER,
    FOREIGN KEY(familly_id) REFERENCES famillies(id),
    FOREIGN KEY(location_id) REFERENCES locations(id)
    );`;

familyTable : string = `CREATE TABLE IF NOT EXISTS famillies (
    id INTEGER PRIMARY KEY,
    reference VARCHAR(32) NOT NULL,
    name TEXT NOT NULL,
    unit VARCHAR);`;

locationTable : string = `CREATE TABLE IF NOT EXISTS locations (
        id INTEGER PRIMARY KEY,
        name TEXT NOT NULL);`;
//Date , Quantity , Unit Cost , Reason (New Stock - Usable Return - Unusable Return ) ,UPC (Universal Product Code ) Comment    
transactionTable : string = `CREATE TABLE IF NOT EXISTS transactions (
        id INTEGER PRIMARY KEY,
        date TEXT,
        quantity REAL,
        unitCost REAL,
        reason VARCHAR,
        upc TEXT,
        comment TEXT,
        product_id INTEGER,
        FOREIGN KEY(product_id) REFERENCES products(id));`;

        async createTables(){
          try {
              await this.database.executeSql(this.familyTable, {});
              await this.database.executeSql(this.locationTable,{});
              await this.database.executeSql(this.productTable,{});
              await this.database.executeSql(this.transactionTable,{});
          }catch(e){
              console.log("Error !");
          }
      }

        constructor(public sqlite :SQLite) {
          console.log('Hello DataServiceProvider Provider')

              this.sqlite.create({name: "data.db", location: "default"}).then((db : SQLiteObject) => {
                      this.database = db;
                  }, (error) => {
                      console.log("ERROR: ", error);
              }); 
    }

}

有谁知道如何解决它?

最佳答案

executeSql的签名为:

executeSql(statement: string, params?: any[]): Promise<any>;

如果您使用{}作为第二个参数调用executeSql,那么我知道您不想传递任何参数。所以你应该这样调用方法:
await this.database.executeSql(this.familyTable);
await this.database.executeSql(this.locationTable);
await this.database.executeSql(this.productTable);
await this.database.executeSql(this.transactionTable);

关于angularjs - 在 'Argument of type '类型中,如何解决}' is not assignable to parameter of type ' {]'. [ng] Property ' any [ '{}' length'丢失了。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55385611/

相关文章:

javascript - 通过 $http 进行 Angular json 编码

css - AngularJS 指令观察父级高度变化

javascript - 在 Ionic 2 上动态更新标签徽章

angular - 类型 ClassB 中的属性 x 不可分配给基类型 ClassA 中的相同属性

sqlite - Xamarin.Forms SQLite CreateTableAsync()返回类型的用法

database - 是否可以在 Palm Pre 上预加载 Sqlite DB?

javascript - Angular $http.post 不发送任何数据

php - JavaScript 促进了 OpenID 登录?

node.js - typescript 错误——错误 : Cannot find module 'typescript/tsc.js'

python - 如果我不关闭 Python SQLite 中的数据库连接怎么办