-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
type-challenges-solutions/en/medium-objectentries #304
Labels
Comments
This doesn't work for such cases Expect<Equal<ObjectEntries<{ key: 1 | undefined }>, ['key', 1 | undefined]>>,
Expect<Equal<ObjectEntries<{ key?: 1 | undefined }>, ['key', 1 | undefined]>>, |
@zhaoyao91 did you manage to improve the solution to get those tests passing? |
@ghaiklor sadlly, I didn't find a perfect solution yet. Naive solution would indeed pass most cases but the |
This is my solution so far type ObjectEntries<
T extends Record<keyof any, any>,
K extends keyof T = keyof T
> = K extends any
? [K, Required<T>[K] extends never ? undefined : Required<T>[K]]
: never; |
Here is my solution: all test cases passed:
|
Update:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ObjectEntries
This project is aimed at helping you better understand how the type system works, writing your own utilities, or just having fun with the challenges.
https://ghaiklor.github.io/type-challenges-solutions/en/medium-objectentries.html
The text was updated successfully, but these errors were encountered: