@@ -298,13 +298,17 @@ if (y) {
298
298
declare const x: null; if (x) {}
299
299
(x: undefined) => !x;
300
300
<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;
301
303
` ,
302
304
errors : [
303
305
{ messageId : 'conditionErrorNullish' , line : 2 , column : 1 } ,
304
306
{ messageId : 'conditionErrorNullish' , line : 3 , column : 9 } ,
305
307
{ messageId : 'conditionErrorNullish' , line : 4 , column : 36 } ,
306
308
{ messageId : 'conditionErrorNullish' , line : 5 , column : 28 } ,
307
309
{ messageId : 'conditionErrorNullish' , line : 6 , column : 47 } ,
310
+ { messageId : 'conditionErrorNullish' , line : 7 , column : 35 } ,
311
+ { messageId : 'conditionErrorNullish' , line : 8 , column : 40 } ,
308
312
] ,
309
313
} ) ,
310
314
@@ -316,13 +320,19 @@ if (y) {
316
320
declare const x: symbol; if (x) {}
317
321
(x: () => void) => !x;
318
322
<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;
319
326
` ,
320
327
errors : [
321
328
{ messageId : 'conditionErrorObject' , line : 2 , column : 1 } ,
322
329
{ messageId : 'conditionErrorObject' , line : 3 , column : 10 } ,
323
330
{ messageId : 'conditionErrorObject' , line : 4 , column : 38 } ,
324
331
{ messageId : 'conditionErrorObject' , line : 5 , column : 29 } ,
325
332
{ 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 } ,
326
336
] ,
327
337
} ) ,
328
338
@@ -843,12 +853,12 @@ if (y) {
843
853
} ) ,
844
854
845
855
// 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)
847
856
...batchedSingleLineTests < MessageId , Options > ( {
848
857
code : noFormat `
849
858
if (x) {}
850
859
x => !x;
851
860
<T extends any>(x: T) => x ? 1 : 0;
861
+ <T>(x: T) => x ? 1 : 0;
852
862
` ,
853
863
errors : [
854
864
{
@@ -884,6 +894,17 @@ if (y) {
884
894
} ,
885
895
] ,
886
896
} ,
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
+ } ,
887
908
] ,
888
909
} ) ,
889
910
0 commit comments