#Q['length'] extends 4 but number does not extend Q['length']

6 messages · Page 1 of 1 (latest)

sly eagle
#

How come the length of the tuple is 4 but it's false that number extends Q['length'] ?

  type ABC = number extends Q['length'] ? true : false // false

  type DEF = Q['length'] extends 4 ? true : false //true```
hollow echo
#

because number doesn't extend 4. here's a simpler example:

woven yarrowBOT
#
type X = number extends 4 ? true : false
//   ^? - type X = false
hollow echo
#

4 extends number, not the other way around

sly eagle
#

Thank you. In this type hero challenge, the solution for isTuple does this type IsTuple<T> = [T] extends [never] ? false : T extends readonly unknown[] ? number extends T["length"] ? false : true : false; What does it mean when it says number extends T["length"]? if number does not extend 4, why would you check if number extends T["length"] isn't that the same thing? https://typehero.dev/challenge/istuple/solutions/1713```

hollow echo
#

number extends T["length"] will be true when T is an arbitrary-length array type. try IsTuple<string[]> for example