Type alias ImmutableKeys<T>

ImmutableKeys<T>: {
    [P in Keys<T>]: Equals<Pick<T, P>, Readonly<Pick<T, P>>> extends true
        ? P
        : never
}[Keys<T>]

Retrieves the keys that are immutable (readonly) from an object of type T.

Type Parameters

  • T

Example

 type ExampleType = {
a: number;
readonly b: string;
c: {
a: string;
d: { readonly x: Nullable; v: Maybe<Newable> };
};
};

type ImmutableKeysOfExampleType = ImmutableKeys<ExampleType>;
// Result: 'b'