简体   繁体   English

类型错误:超级表达式必须为空或函数 _inherits

[英]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.

相关问题 类型错误:超级表达式必须为空或反应本机中的函数_inherits - TypeError: Super expression must either be null or a function _inherits in react native TypeError:超级表达式必须为null或函数 - TypeError: Super expression must either be null or a function TypeError:超级表达式必须是 null 或 React native 中的 function - TypeError: Super expression must either be null or a function in React native TypeError:超级表达式必须为null或函数,且未定义 - TypeError: Super expression must either be null or a function, not undefined React Native,TypeError:超级表达式必须为空或函数 - React Native, TypeError: Super expression must either be null or a function 超级表达式必须为null或函数,而不是对象 - Super expression must either be null or a function, not object nodejs 超级表达式必须是 null 或 function - nodejs Super expression must either be null or a function babel 或 webpack 或我的代码导致此错误“未捕获的类型错误:超级表达式必须是 null 或函数” - either babel or webpack or my code are causing this error "Uncaught TypeError: Super expression must either be null or a function" TypeError(“超级表达式必须是 null 或函数”) - 当 App 是 class 而不是 function 时 - TypeError(“Super expression must either be null or a function”) - when App is a class instead of a function 使用webpack的react-redux给出错误Uncaught TypeError:超级表达式必须为null或函数,且未定义 - react-redux with webpack giving error Uncaught TypeError: Super expression must either be null or a function, not undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM