# IsOptionalKeyOf

`type` in `plugins` · v0.6.1

<https://docs.seedcord.org/packages/plugins/0.6.1/types/is-optional-key-of>

Returns a boolean for whether the given key is an optional key of type.

This is useful when writing utility types or schema validators that need to differentiate `optional` keys.

## Examples

```ts
import type {IsOptionalKeyOf} from 'type-fest';

type User = {
	name: string;
	surname: string;

	luckyNumber?: number;
};

type Admin = {
	name: string;
	surname?: string;
};

type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
//=> true

type T2 = IsOptionalKeyOf<User, 'name'>;
//=> false

type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
//=> boolean

type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
//=> false

type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
//=> boolean

 Type Guard   Utilities
```

## Declaration

```ts
type IsOptionalKeyOf<Type extends object, Key extends keyof Type> =
    IsAny<Type | Key> extends true
        ? never
        : Key extends keyof Type
          ? Type extends Record<Key, Type[Key]>
              ? false
              : true
          : false;
```
