Back to Type Challenges

README

questions/02857-hard-isrequiredkey/README.md

latest1.3 KB
Original Source
<!--info-header-start--><h1>IsRequiredKey </h1><blockquote><p>by jiangshan <a href="https://github.com/jiangshanmeta" target="_blank">@jiangshanmeta</a></p></blockquote><p><a href="https://tsch.js.org/2857/play" target="_blank"></a> </p><!--info-header-end-->

Implement a generic IsRequiredKey<T, K> that return whether K are required keys of T .

For example

typescript
type A = IsRequiredKey<{ a: number, b?: string },'a'> // true
type B = IsRequiredKey<{ a: number, b?: string },'b'> // false
type C = IsRequiredKey<{ a: number, b?: string },'b' | 'a'> // false
<!--info-footer-start-->

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