https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#uncalled-function-checks
関数を呼び出さずにif文で判定したとき、呼び忘れの可能性が高いケースでエラーを出すようになった。
```ts
interface Hoge {
required(): boolean;
}
declare const hoge: Hoge;
// This condition will always return true since the function is always defined. Did you mean to call it instead?
// 『必ずtrueを返すfunctionが条件になっている、呼び忘れではないか?』とエラーが出る
if (hoge.required) {
console.log("required!!");
}
```
呼び忘れである可能性が低い場合はエラーにならない。
## エラーにならないケース
[[--strictNullChecks]]がOFFである場合はエラーにならない。[[--strictNullChecks]]がONである場合は以下3つのケースではそれぞれエラーにならない。
### functionがoptionalの場合
functionが`undefined`や`null`になりえる場合。存在確認であるとみなせる。
```ts
interface Hoge {
optional?(): boolean;
}
declare const hoge: Hoge;
if (hoge.optional) {
console.log("required!!");
}
```
### 存在すると判定されたfunctionを呼び出す場合
判定したfunctionをif文の中で使う場合。
```ts
interface Hoge {
required(): boolean
}
declare const hoge: Hoge;
if (hoge.required) {
console.log(hoge.required())
// 呼び出さなくてもOK (だけどこれだと呼び忘れの可能性もあるのでは..🤔)
console.log(hoge.required)
}
```
###
### 二重否定で判定する場合
意図的であり呼び忘れではないと判断できるため。
```ts
interface Hoge {
required(): boolean
}
declare const hoge: Hoge;
if (!!hoge.required) {
console.log("required")
}
```