#How do I test for an empty tuple in a conditional type

5 messages · Page 1 of 1 (latest)

wary torrent
#

if the following is always true

type IsEmpty<T extends unknown[]> = T extends [] ? true : false; 

How do I test for T being an empty tuple?

#

T extends { length: 0 } works

summer belfryBOT
#
type IsEmpty<T extends unknown[]> = T extends [] ? true : false; 
type T = IsEmpty<1[]>;
//   ^? - type T = false
#
type IsEmpty<T extends unknown[]> = T extends [] ? true : false; 
type T = IsEmpty<[1]>;
//   ^? - type T = false
hollow arrow
#

@wary torrent wdym it always returns true?