Skip to content

Commit 61696e4

Browse files
committed
feat: add 0089-hard-required-keys
1 parent 0743b29 commit 61696e4

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type RequiredKeys<T> = keyof {
2+
[K in keyof T as T[K] extends Required<T>[K] ? K : never]: T[K];
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Equal, Expect } from "@type-challenges/utils";
2+
3+
type cases = [
4+
Expect<Equal<RequiredKeys<{ a: number; b?: string }>, "a">>,
5+
Expect<Equal<RequiredKeys<{ a: undefined; b?: undefined }>, "a">>,
6+
Expect<
7+
Equal<
8+
RequiredKeys<{ a: undefined; b?: undefined; c: string; d: null }>,
9+
"a" | "c" | "d"
10+
>
11+
>,
12+
Expect<Equal<RequiredKeys<{}>, never>>
13+
];

0 commit comments

Comments
 (0)