简体   繁体   中英

How can I change the way a lodash function is used for Typescript?

I have this code:

    _.remove(this.home.modal.data.roles, function (currentObject) {
        return currentObject.name === roleToDelete;
    });

Can someone tell me how I can change the function call to the way it's usually done with Typescript. Also it gives me an error:

    Message 118 TsLint: expected callSignature to have a typedef.

Any suggestions would be appreciated.

Is this what you're looking for:

_.remove(this.home.modal.data.roles, (currentObject) => {
    return currentObject.name === roleToDelete;
});

You can also type your "currentObject" like this:

_.remove(this.home.modal.data.roles, (currentObject: Role) => {
    return currentObject.name === roleToDelete;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM