We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0743b29 commit 61696e4Copy full SHA for 61696e4
type-challenges/0089-hard-required-keys/template.ts
@@ -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
+};
type-challenges/0089-hard-required-keys/test-cases.ts
@@ -0,0 +1,13 @@
+import type { Equal, Expect } from "@type-challenges/utils";
+
+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