如何禁用特定行的ts规则?

Summernote是一个jQuery插件,我不需要它的类型定义。 我只想修改对象,但TS不断抛出错误。 下面的一行仍然告诉我: “’jQueryStatic’类型中不存在”属性’summernote’。“ 错误。

(function ($) { /* tslint:disable */ delete $.summernote.options.keyMap.pc.TAB; delete $.summernote.options.keyMap.mac.TAB; /* tslint:enable */ })(jQuery) 

编辑:

这是我的tsconfig.json

 { "compilerOptions": { "outDir": "./dist/", "sourceMap": true, "noImplicitAny": true, "module": "commonjs", "target": "es5", "allowJs": true, "noUnusedParameters": true }, "include": [ "js/**/*" ], "exclude": [ "node_modules", "**/*.spec.ts" ] } 

您可以使用/* tslint:disable-next-line */来本地禁用tslint。 但是,由于这是编译器错误,因此禁用tslint可能无济于事。

您可以随时暂时将$any

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

这将允许您访问您想要的任何属性。

与此答案类似,您可以覆盖JQueryStatic类型定义以包含summernote属性。

 interface JQueryStatic { // Opt out of type-checking summernote using the any type // See https://www.typescriptlang.org/docs/handbook/basic-types.html#any summernote: any } (function ($) { delete $.summernote.options.keyMap.pc.TAB; delete $.summernote.options.keyMap.mac.TAB; })(jQuery)