[英]TypeError: Super expression must either be null or a function _inherits
I am getting this error:我收到此错误:
Super expression must either be null or a function超级表达式必须为 null 或函数
in the following code snippet:在以下代码片段中:
import SQLite from 'react-native-sqlite-storage';
const DB = SQLite.openDatabase('Data.db');
class Database {
db;
constructor(db) {
this.db = db;
}
executeSql = (sql, params = []) =>
new Promise((resolve, reject) => {
this.db.transaction((trans) => {
trans.executeSql(
sql,
params,
(db, results) => {
resolve(results);
},
(error) => {
reject(error);
}
);
});
});
}
export default new Database(DB);
import Database from '../db';
export class Note extends Database {
constructor() {
super();
}
all = () => async() => {
console.log('all');
const result = await DB.executeSql('Notes', ['params']);
console.log('result', result);
};
}
export default new Note();
Where is my mistake and how can I solve this problem?我的错误在哪里,我该如何解决这个问题?
Your mistake is that you are trying to create a Class ( Note
) that extends another Class ( Database
), but the imported Database
object in the second file is not a Class, but an instantiated Class object.你的错误是你试图创建一个扩展另一个类( Database
)的类( Note
),但第二个文件中导入的Database
对象不是一个类,而是一个实例化的类对象。
You don't need to extend the Database, (and you can't, since it's not a Class).你不需要扩展数据库,(你不能,因为它不是一个类)。 You just need to import and use the method directly.您只需要直接导入和使用该方法。
import Database from '../db';
export class Note {
constructor() {
}
all = () => async() => {
console.log('all');
const result = await Database.executeSql('Notes', ['params']);
console.log('result', result);
};
}
export default new Note();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.