import type {IsEqual} from './is-equal.d.ts'; import type {IsAny} from './is-any.d.ts'; /** Returns a boolean for whether the given key is a readonly key of type. This is useful when writing utility types or schema validators that need to differentiate `readonly` keys. @example ``` import type {IsReadonlyKeyOf} from 'type-fest'; interface User { name: string; surname: string; readonly id: number; } interface Admin { name: string; id: string; } type T1 = IsReadonlyKeyOf; //=> true type T2 = IsReadonlyKeyOf; //=> false type T3 = IsReadonlyKeyOf; //=> boolean type T4 = IsReadonlyKeyOf; //=> false type T5 = IsReadonlyKeyOf; //=> boolean ``` @category Type Guard @category Utilities */ export type IsReadonlyKeyOf = IsAny extends true ? never : Key extends unknown // For distributing `Key` ? Type extends unknown // For distributing `Type` ? IsEqual< {[K in Key]: Type[Key]}, {readonly [K in Key]: Type[Key]} > : never // Should never happen : never; // Should never happen export {};