fix(typescript-types): Prevent distribution in IsKeyOf<T,K>

This commit is contained in:
T. R. Bernstein
2025-07-17 16:35:11 +02:00
parent 7decf5ea45
commit 96cf6bbc48
2 changed files with 7 additions and 4 deletions

View File

@@ -1,4 +1,8 @@
import type { If } from './if.js'
import type { IsNever } from './is-never.js'
export type IsKeyOf<T, K> = If<IsNever<T>, false, If<IsNever<K>, false, K extends keyof T ? true : false>>
export type IsKeyOf<Obj, Key> = If<
IsNever<Key>,
false,
[Key] extends [keyof Obj] ? If<IsNever<Obj[Key]>, false, true> : false
>