=== tests/cases/compiler/truthinessCallExpressionCoercion.ts === function onlyErrorsWhenTestingNonNullableFunctionType(required: () => boolean, optional?: () => boolean) { >onlyErrorsWhenTestingNonNullableFunctionType : (required: () => boolean, optional?: (() => boolean) | undefined) => void >required : () => boolean >optional : (() => boolean) | undefined if (required) { // error >required : () => boolean } if (optional) { // ok >optional : (() => boolean) | undefined } if (!!required) { // ok >!!required : true >!required : false >required : () => boolean } if (required()) { // ok >required() : boolean >required : () => boolean } } function onlyErrorsWhenUnusedInBody() { >onlyErrorsWhenUnusedInBody : () => void function test() { return Math.random() > 0.5; } >test : () => boolean >Math.random() > 0.5 : boolean >Math.random() : number >Math.random : () => number >Math : Math >random : () => number >0.5 : 0.5 if (test) { // error >test : () => boolean console.log('test'); >console.log('test') : void >console.log : (...data: any[]) => void >console : Console >log : (...data: any[]) => void >'test' : "test" } if (test) { // ok >test : () => boolean console.log(test); >console.log(test) : void >console.log : (...data: any[]) => void >console : Console >log : (...data: any[]) => void >test : () => boolean } if (test) { // ok >test : () => boolean test(); >test() : boolean >test : () => boolean } if (test) { // ok >test : () => boolean [() => null].forEach(() => { >[() => null].forEach(() => { test(); }) : void >[() => null].forEach : (callbackfn: (value: () => null, index: number, array: (() => null)[]) => void, thisArg?: any) => void >[() => null] : (() => null)[] >() => null : () => null >null : null >forEach : (callbackfn: (value: () => null, index: number, array: (() => null)[]) => void, thisArg?: any) => void >() => { test(); } : () => void test(); >test() : boolean >test : () => boolean }); } if (test) { // error >test : () => boolean [() => null].forEach(test => { >[() => null].forEach(test => { test(); }) : void >[() => null].forEach : (callbackfn: (value: () => null, index: number, array: (() => null)[]) => void, thisArg?: any) => void >[() => null] : (() => null)[] >() => null : () => null >null : null >forEach : (callbackfn: (value: () => null, index: number, array: (() => null)[]) => void, thisArg?: any) => void >test => { test(); } : (test: () => null) => void >test : () => null test(); >test() : null >test : () => null }); } } function checksPropertyAccess() { >checksPropertyAccess : () => void const x = { >x : { foo: { bar(): boolean; }; } >{ foo: { bar() { return true; } } } : { foo: { bar(): boolean; }; } foo: { >foo : { bar(): boolean; } >{ bar() { return true; } } : { bar(): boolean; } bar() { return true; } >bar : () => boolean >true : true } } if (x.foo.bar) { // error >x.foo.bar : () => boolean >x.foo : { bar(): boolean; } >x : { foo: { bar(): boolean; }; } >foo : { bar(): boolean; } >bar : () => boolean } if (x.foo.bar) { // ok >x.foo.bar : () => boolean >x.foo : { bar(): boolean; } >x : { foo: { bar(): boolean; }; } >foo : { bar(): boolean; } >bar : () => boolean x.foo.bar; >x.foo.bar : () => boolean >x.foo : { bar(): boolean; } >x : { foo: { bar(): boolean; }; } >foo : { bar(): boolean; } >bar : () => boolean } } class Foo { >Foo : Foo maybeIsUser?: () => boolean; >maybeIsUser : (() => boolean) | undefined isUser() { >isUser : () => boolean return true; >true : true } test() { >test : () => void if (this.isUser) { // error >this.isUser : () => boolean >this : this >isUser : () => boolean } if (this.maybeIsUser) { // ok >this.maybeIsUser : (() => boolean) | undefined >this : this >maybeIsUser : (() => boolean) | undefined } } } // Test for GH-35557 where ids were not assigned for a symbol. function A(stats: StatsBase) { >A : (stats: StatsBase) => void >stats : StatsBase if (stats.isDirectory) { // err >stats.isDirectory : () => boolean >stats : StatsBase >isDirectory : () => boolean console.log(`[Directory] ${stats.ctime}`) >console.log(`[Directory] ${stats.ctime}`) : void >console.log : (...data: any[]) => void >console : Console >log : (...data: any[]) => void >`[Directory] ${stats.ctime}` : string >stats.ctime : number >stats : StatsBase >ctime : number } } function B(a: Nested, b: Nested) { >B : (a: Nested, b: Nested) => void >a : Nested >b : Nested if (a.stats.isDirectory) { // err >a.stats.isDirectory : () => boolean >a.stats : StatsBase >a : Nested >stats : StatsBase >isDirectory : () => boolean b.stats.isDirectory(); >b.stats.isDirectory() : boolean >b.stats.isDirectory : () => boolean >b.stats : StatsBase >b : Nested >stats : StatsBase >isDirectory : () => boolean } if (a.stats.isDirectory) { // ok >a.stats.isDirectory : () => boolean >a.stats : StatsBase >a : Nested >stats : StatsBase >isDirectory : () => boolean a.stats.isDirectory(); >a.stats.isDirectory() : boolean >a.stats.isDirectory : () => boolean >a.stats : StatsBase >a : Nested >stats : StatsBase >isDirectory : () => boolean } } interface StatsBase { isDirectory(): boolean; >isDirectory : () => boolean ctime: number; >ctime : number } interface Nested { stats: StatsBase; >stats : StatsBase }