Created
July 21, 2020 18:40
-
-
Save karol-majewski/ce726e3dd26a208de7545189a6285fe8 to your computer and use it in GitHub Desktop.
Pick properties from a TypeScript type by their value
This file contains hidden or 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
interface Dog { | |
name: string; | |
bark(): void; | |
} | |
declare global { | |
namespace Pick { | |
type ByValue<T, U> = Pick<T, PropertyOfValue<T, U>> | |
} | |
} | |
type PropertyOfValue<T, V> = { | |
[K in keyof T]-?: T[K] extends V | |
? K | |
: never | |
}[keyof T]; | |
type Methods = Pick.ByValue<Dog, Function> // { bark(): void } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment