Javascript Can';在typescript中不使用类内函数吗?

Javascript Can';在typescript中不使用类内函数吗?,javascript,typescript,ecmascript-6,Javascript,Typescript,Ecmascript 6,使用class选项,我计划在typescript中创建一个包含CRUD操作函数的类。(比如CreateStudent()、updateStudent()、listStudents()、ViewStudent())所以首先我创建了一个listStudent函数 class student { listStudent (apiUrl:string) { this.usePromise(apiUrl).then(function(){ console.l

使用class选项,我计划在typescript中创建一个包含CRUD操作函数的类。(比如CreateStudent()、updateStudent()、listStudents()、ViewStudent())所以首先我创建了一个listStudent函数

class student {
    listStudent (apiUrl:string) {
        this.usePromise(apiUrl).then(function(){
            console.log("api call completed");
        });
    }

    usePromise<T>(apiUrl:string):Promise<T> {
        let p: Promise<T>;
        p = new Promise(() => {
        var request = new XMLHttpRequest();
        request.onreadystatechange = function() {
            ...
        }
            ...
    });
    return p;
    }
}
let s:student = new student();
s.listStudent("api/list.php");
我说了一个错误

泛型类型“Promise”需要1个参数

因此,我阅读了有关泛型类型的内容,然后在usePromise函数中实现了它。现在,我在创建promise对象时遇到一个错误

Promise仅引用类型,但在此处用作变量

  • 为什么会出现这个错误,我正确地将promise声明为创建该类型对象的返回类型
  • 取而代之的是,无论我在任何类函数中尝试创建一个promise对象,我都会得到相同的错误

您检查过这些问题吗?是否编译?或者tslint甚至在编译之前就给您出了错误?我只是使用了纯ts文件,并使用tsc命令运行它。目标ES6似乎没有问题,但现在在XMLHttprequest和console上显示了错误。logI使用这些编译器选项更新了我的代码
{“compilerOptions”:{“module”:“commonjs”,“noImplicitAny”:false,“removeComments”:true,“preserveConstEnums”:true,“sourceMap”:true,“lib”:[“es6”、“dom”、“dom.iterable”、“scripthost”]},“文件”:[“student.ts”]}
usePromise(apiUrl:string):Promise {}