Created
October 9, 2022 01:57
-
-
Save semlinker/e643c0ca8ca127b34a6459bfc9a697d8 to your computer and use it in GitHub Desktop.
From T, pick a set of properties whose type are assignable to U.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type PickByType<T, U> = { | |
[P in keyof T as T[P] extends U ? P : never]: T[P]; | |
}; | |
type OnlyBoolean = PickByType< | |
{ | |
name: string; | |
count: number; | |
isReadonly: boolean; | |
isEnable: boolean; | |
}, | |
boolean | |
>; // { isReadonly: boolean; isEnable: boolean; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment