How to disable a ts rule for a specific line?

后端 未结 2 1088
感情败类
感情败类 2021-02-04 22:46

Summernote is a jQuery plugin, and I don\'t need type definitions for it. I just want to modify the object, but TS keeps throwing errors. The line bellow still gives me:

2条回答
  •  我在风中等你
    2021-02-04 23:32

    You can use /* tslint:disable-next-line */ to locally disable tslint. However, as this is a compiler error disabling tslint might not help.

    You can always temporarily cast $ to any:

    delete ($ as any).summernote.options.keyMap.pc.TAB
    

    which will allow you to access whatever properties you want.


    Edit: As of Typescript 2.6, you can now bypass a compiler error/warning for a specific line:

    if (false) {
        // @ts-ignore: Unreachable code error
        console.log("hello");
    }
    

    Note that the official docs "recommend you use [this] very sparingly". It is almost always preferable to cast to any instead as that better expresses intent.

提交回复
热议问题