snippetjavascriptCritical
How to disable a ts rule for a specific line?
Viewed 0 times
howdisablelineruleforspecific
Problem
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: "Property 'summernote' does not exist on type 'jQueryStatic'." error.
Edit:
Here is my tsconfig.json
(function ($) {
/* tslint:disable */
delete $.summernote.options.keyMap.pc.TAB;
delete $.summernote.options.keyMap.mac.TAB;
/* tslint:enable */
})(jQuery)Edit:
Here is my tsconfig.json
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"allowJs": true,
"noUnusedParameters": true
},
"include": [
"js/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}Solution
As of Typescript 2.6, you can now bypass a compiler error/warning for a specific line:
Note that the official docs "recommend you use [this] very sparingly". It is almost always preferable to cast to
Older answer:
You can use
You can always temporarily cast
which will allow you to access whatever properties you want.
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.Older answer:
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.TABwhich will allow you to access whatever properties you want.
Code Snippets
if (false) {
// @ts-ignore: Unreachable code error
console.log("hello");
}delete ($ as any).summernote.options.keyMap.pc.TABContext
Stack Overflow Q#43618878, score: 382
Revisions (0)
No revisions yet.