Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js ';这';隐式具有类型';任何';因为它没有类型注释。ts(2683)_Node.js_Typescript - Fatal编程技术网

Node.js ';这';隐式具有类型';任何';因为它没有类型注释。ts(2683)

Node.js ';这';隐式具有类型';任何';因为它没有类型注释。ts(2683),node.js,typescript,Node.js,Typescript,我从“this”中得到以下错误: “this”隐式具有类型“any”,因为它没有类型 注释.ts(2683) 我听说问题来自箭头键,但我没有使用箭头键作为回调函数?我仍然得到一个错误。有什么好处 我还从“完成”中得到一个错误: 参数“done”隐式具有“any”类型。ts(7006) 这可能是Visual Studio代码中的某种错误吗?您是否尝试过执行以下操作,我也遇到过同样的问题,并且我一直在努力解决这些问题 userSchema.pre('save', async function(don

我从“this”中得到以下错误:

“this”隐式具有类型“any”,因为它没有类型 注释.ts(2683)

我听说问题来自箭头键,但我没有使用箭头键作为回调函数?我仍然得到一个错误。有什么好处

我还从“完成”中得到一个错误:

参数“done”隐式具有“any”类型。ts(7006)


这可能是Visual Studio代码中的某种错误吗?

您是否尝试过执行以下操作,我也遇到过同样的问题,并且我一直在努力解决这些问题

userSchema.pre('save', async function(done) {
    if (this.isModified('pass')) {
        const hashed = await Password.toHash(this.get('pass'));
        this.set('pass', hashed);
    }
    done();
});

据我所知,错误源于typescript配置,可以对其进行隐式键入修改,以避免显示错误。

您是否尝试过以下操作,我也遇到过同样的问题,我也曾这样做过

userSchema.pre('save', async function(done) {
    if (this.isModified('pass')) {
        const hashed = await Password.toHash(this.get('pass'));
        this.set('pass', hashed);
    }
    done();
});

据我所知,错误源于typescript配置,可以修改该配置以进行隐式键入,从而不显示错误。

这不是VS代码或typescript中的错误。很简单,对TypeScript的调用没有足够的信息来确定当Mongoose最终执行函数时,这个将绑定到什么

假设您有一个名为
User
的类型,您可以使用显式
this
类型注释来修复此问题

// We generally explicitly provide a type to the arguments we are using...

userSchema.pre('save', async function(done: any) {
    const self: any = this;

    if (this.isModified('pass')) {
        const hashed = await Password.toHash(self.get('pass'));
        self.set('pass', hashed);
    }
    done();
});

请注意,用于指定
this
类型的语法是一种特殊语法,因为它不会在生成的JavaScript中发出参数:

userSchema.pre('save', async function(this: User, done) {
    if (this.isModified('pass')) {
        const hashed = await Password.toHash(this.get('pass'));
        this.set('pass', hashed);
    }
    done();
});
编译成

function(this: X) {}

这不是VS代码或TypeScript中的错误。很简单,对TypeScript的调用没有足够的信息来确定当Mongoose最终执行函数时,这个将绑定到什么

假设您有一个名为
User
的类型,您可以使用显式
this
类型注释来修复此问题

// We generally explicitly provide a type to the arguments we are using...

userSchema.pre('save', async function(done: any) {
    const self: any = this;

    if (this.isModified('pass')) {
        const hashed = await Password.toHash(self.get('pass'));
        self.set('pass', hashed);
    }
    done();
});

请注意,用于指定
this
类型的语法是一种特殊语法,因为它不会在生成的JavaScript中发出参数:

userSchema.pre('save', async function(this: User, done) {
    if (this.isModified('pass')) {
        const hashed = await Password.toHash(this.get('pass'));
        this.set('pass', hashed);
    }
    done();
});
编译成

function(this: X) {}