Home > types-kit > ConditionalKeys
Get keys by Condition (value).
Signature:
export type ConditionalKeys<T, Condition, Exact extends boolean = false> = {
[K in Keys<T>]: Exact extends true
? T[K] extends Condition
? K
: never
: T[K] extends infer V
? V extends Condition
? K
: never
: never
}[Keys<T>]References: Keys
interface Props {
a?: number
b: string
c: boolean
}
// Expect: 'b' | 'c'
type PropKeys = ConditionalKeys<Props, string | boolean>
// Set exact true, expect: 'c'
type PropKeys2 = ConditionalKeys<Props, string | boolean, true>