#[T] extends [never] ...

2 messages · Page 1 of 1 (latest)

ember dome
#

In one of the solutions to a typehero challenges "IsTuple", there is an idiom used
[T] extends [never]
https://typehero.dev/challenge/istuple/solutions/1713
Full solution

  ? false
  : T extends readonly unknown[]
  ? number extends T["length"]
    ? false
    : true
  : false;```

My question. What is the point of `[T] extends [never]`?

Playing around with it, you can see below that there's a difference between passing A<[never]> and A<never>

  ```type A<T> = [T] extends [never] ? true : false
  type B = A<[never]>//false
  type C = A<never>//true```
TypeHero

Level up and learn TypeScript with interactive exercises

turbid lake