-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1042-isnever.ts
33 lines (29 loc) · 963 Bytes
/
1042-isnever.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* 1042 - IsNever
*
* Implement a type IsNever, which takes input type `T`.
* If the type of resolves to `never`, return `true`, otherwise `false`.
*
* For example:
*
* ```ts
* type A = IsNever<never> // expected to be true
* type B = IsNever<undefined> // expected to be false
* type C = IsNever<null> // expected to be false
* type D = IsNever<[]> // expected to be false
* type E = IsNever<number> // expected to be false
* ```
*/
/* _____________ Your Code Here _____________ */
type IsNever<T> = [T] extends [never] ? true : false;
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<IsNever<never>, true>>,
Expect<Equal<IsNever<never | string>, false>>,
Expect<Equal<IsNever<''>, false>>,
Expect<Equal<IsNever<undefined>, false>>,
Expect<Equal<IsNever<null>, false>>,
Expect<Equal<IsNever<[]>, false>>,
Expect<Equal<IsNever<{}>, false>>,
]