SummernoteはjQueryのプラグインで、そのための型定義は必要ありません。オブジェクトを変更したいだけなのですが、TSがエラーを出し続けます。以下の行はまだ私に与えます。"Property 'summernote' does not exist on type 'jQueryStatic'."エラーが発生します。
(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 を無効にするには、/* tslint:disable-next-line */
を使用します。しかし、これはコンパイラエラーなので、tslintを無効にしても効果がないかもしれません。
常に一時的に $
を any
にキャストすることができます。
delete ($ as any).summernote.options.keyMap.pc.TAB
に一時的にキャストすることができます。これにより、必要なプロパティにアクセスすることができます。
編集:Typescript 2.6では、特定の行のコンパイラエラー/警告を回避することができるようになりました。
if (false) {
// @ts-ignore: Unreachable code error
console.log("hello");
}
なお、公式ドキュメントでは "recommend you use [this] very sparingly"となっています。代わりに any
にキャストする方が意図をよりよく表現できるので、ほとんど常に*好ましいです。
この回答](https://stackoverflow.com/a/24984067/1798762)と同様に、`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)