Skip to content

Commit 852f1d8

Browse files
committed
1 parent e999e36 commit 852f1d8

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/isNever.ts

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
1042 - IsNever
3+
-------
4+
by hiroya iizuka (@hiroyaiizuka) #medium #union #utils
5+
6+
### Question
7+
8+
Implement a type IsNever, which takes input type `T`.
9+
If the type of resolves to `never`, return `true`, otherwise `false`.
10+
11+
For example:
12+
13+
```ts
14+
type A = IsNever<never> // expected to be true
15+
type B = IsNever<undefined> // expected to be false
16+
type C = IsNever<null> // expected to be false
17+
type D = IsNever<[]> // expected to be false
18+
type E = IsNever<number> // expected to be false
19+
```
20+
21+
> View on GitHub: https://tsch.js.org/1042
22+
*/
23+
24+
/* _____________ Your Code Here _____________ */
25+
26+
type IsNever<T> = [T] extends [never] ? true : false;
27+
28+
/* _____________ Test Cases _____________ */
29+
import type { Equal, Expect } from "@type-challenges/utils";
30+
31+
type cases = [
32+
Expect<Equal<IsNever<never>, true>>,
33+
Expect<Equal<IsNever<never | string>, false>>,
34+
Expect<Equal<IsNever<"">, false>>,
35+
Expect<Equal<IsNever<undefined>, false>>,
36+
Expect<Equal<IsNever<null>, false>>,
37+
Expect<Equal<IsNever<[]>, false>>,
38+
Expect<Equal<IsNever<{}>, false>>
39+
];
40+
41+
/* _____________ Further Steps _____________ */
42+
/*
43+
> Share your solutions: https://tsch.js.org/1042/answer
44+
> View solutions: https://tsch.js.org/1042/solutions
45+
> More Challenges: https://tsch.js.org
46+
*/

0 commit comments

Comments
 (0)