'Test if a type is any[] or unknown[]
How does one test if a type is strictly unknown[] or any[]?
Related, but not relevant, these are how I'm testing for other types:
type IsStrictAny<T> = 0 extends (1 & T) ? T : never;
type IsNotStrictAny<T> = T extends IsStrictAny<T> ? never : T
type IsVoid<T> = T extends void ? T : never
type IsStrictVoid<T> = IsVoid<T> & IsNotStrictAny<T>
type IsStrictNever<T> = [T] extends [never] ? true : false
type IsStrictUnknown<T> = T extends IsStrictAny<T> ? never : unknown extends T ? T : never
If there are better ways to do this then that would also be appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
