Back to Type Challenges

README

questions/28143-hard-optionalundefined/README.md

latest1.6 KB
Original Source
<!--info-header-start--><h1>OptionalUndefined </h1><blockquote><p>by Jesus The Hun <a href="https://github.com/JesusTheHun" target="_blank">@JesusTheHun</a></p></blockquote><p><a href="https://tsch.js.org/28143/play" target="_blank"></a> </p><!--info-header-end-->

Implement the util type OptionalUndefined<T, Props> that turns all the properties of T that can be undefined, into optional properties. In addition, a second -optional- generic Props can be passed to restrict the properties that can be altered.

ts
OptionalUndefined<{ value: string | undefined, description: string }>
// { value?: string | undefined; description: string }

OptionalUndefined<{ value: string | undefined, description: string | undefined, author: string | undefined }, 'description' | 'author'>
// { value: string | undefined; description?: string | undefined, author?: string | undefined }
<!--info-footer-start-->

<a href="../../README.md" target="_blank"></a> <a href="https://tsch.js.org/28143/answer" target="_blank"></a> <a href="https://tsch.js.org/28143/solutions" target="_blank"></a> <!--info-footer-end-->