@@ -298,13 +298,17 @@ if (y) {
298298 declare const x: null; if (x) {}
299299 (x: undefined) => !x;
300300 <T extends null | undefined>(x: T) => x ? 1 : 0;
301+ <T extends null>(x: T) => x ? 1 : 0;
302+ <T extends undefined>(x: T) => x ? 1 : 0;
301303 ` ,
302304 errors : [
303305 { messageId : 'conditionErrorNullish' , line : 2 , column : 1 } ,
304306 { messageId : 'conditionErrorNullish' , line : 3 , column : 9 } ,
305307 { messageId : 'conditionErrorNullish' , line : 4 , column : 36 } ,
306308 { messageId : 'conditionErrorNullish' , line : 5 , column : 28 } ,
307309 { messageId : 'conditionErrorNullish' , line : 6 , column : 47 } ,
310+ { messageId : 'conditionErrorNullish' , line : 7 , column : 35 } ,
311+ { messageId : 'conditionErrorNullish' , line : 8 , column : 40 } ,
308312 ] ,
309313 } ) ,
310314
@@ -316,13 +320,19 @@ if (y) {
316320 declare const x: symbol; if (x) {}
317321 (x: () => void) => !x;
318322 <T extends object>(x: T) => x ? 1 : 0;
323+ <T extends Object | Function>(x: T) => x ? 1 : 0;
324+ <T extends { a: number }>(x: T) => x ? 1 : 0;
325+ <T extends () => void>(x: T) => x ? 1 : 0;
319326 ` ,
320327 errors : [
321328 { messageId : 'conditionErrorObject' , line : 2 , column : 1 } ,
322329 { messageId : 'conditionErrorObject' , line : 3 , column : 10 } ,
323330 { messageId : 'conditionErrorObject' , line : 4 , column : 38 } ,
324331 { messageId : 'conditionErrorObject' , line : 5 , column : 29 } ,
325332 { messageId : 'conditionErrorObject' , line : 6 , column : 37 } ,
333+ { messageId : 'conditionErrorObject' , line : 7 , column : 48 } ,
334+ { messageId : 'conditionErrorObject' , line : 8 , column : 44 } ,
335+ { messageId : 'conditionErrorObject' , line : 9 , column : 41 } ,
326336 ] ,
327337 } ) ,
328338
@@ -843,12 +853,12 @@ if (y) {
843853 } ) ,
844854
845855 // any in boolean context
846- // TODO: when `T` is not `extends any` then the error is `conditionErrorObject` (says it's always truthy, which is false)
847856 ...batchedSingleLineTests < MessageId , Options > ( {
848857 code : noFormat `
849858 if (x) {}
850859 x => !x;
851860 <T extends any>(x: T) => x ? 1 : 0;
861+ <T>(x: T) => x ? 1 : 0;
852862 ` ,
853863 errors : [
854864 {
@@ -884,6 +894,17 @@ if (y) {
884894 } ,
885895 ] ,
886896 } ,
897+ {
898+ messageId : 'conditionErrorAny' ,
899+ line : 5 ,
900+ column : 22 ,
901+ suggestions : [
902+ {
903+ messageId : 'conditionFixCastBoolean' ,
904+ output : ' <T>(x: T) => (Boolean(x)) ? 1 : 0;' ,
905+ } ,
906+ ] ,
907+ } ,
887908 ] ,
888909 } ) ,
889910
0 commit comments