私はno-null-keyword
を有効にして、しばらくの間tslintを使用していました。最近、Typescript 2.0にアップグレードし、--strictNullChecking
を有効にしました。しかし、Typescriptのlib.d.ts
を見ると、一部の呼び出しの結果がnull
になる可能性があるので、一見してno-null-keyword
を有効にしておくことは不可能です。たとえば:tslint nullでないキーワードとtypescriptのlib.d.tsが厳密なヌルチェック付き
const result: RegExpExecArray | null = regex.exec(regexStr);
if (result === null) { // <-- tslint complains about this check
throw new Error("Foo location: result of regex is null.");
}
// or
// if (result !== null) {
// ...do something
// }
質問は、右のもの-TO-DOは何かありますか?
無効no-null-keyword
tslint? (?):
const result: RegExpExecArray = regex.exec(regexStr)!;
if (result == undefined) { // Will check if result is undefined or null
throw new Error("Foo location: result of regex is null.");
}
それとも何か他
はハックを使用しますか?
うん、私は質問をしているので、それは私が今までやっていたまさにですfoo == undefined'または 'foo!= undefined'というコードと、理由を明確にした適切なコメントとともに、「allow-undefined-check」]' を入力してください。 – vladeck