Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/actionify/src/deps/types.ts>OptionalKeysOf

Create and manage your GitHub workflows with TypeScript and Deno.
Latest
type alias OptionalKeysOf
import { type OptionalKeysOf } from "https://deno.land/x/actionify@0.3.0/src/deps/types.ts";

Extract all optional keys from the given type.

This is useful when you want to create a new type that contains different type values for the optional keys only.

Examples

Example 1

import type {OptionalKeysOf, Except} from 'type-fest';

interface User {
	name: string;
	surname: string;

	luckyNumber?: number;
}

const REMOVE_FIELD = Symbol('remove field symbol');
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
	[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
};

const update1: UpdateOperation<User> = {
	name: 'Alice'
};

const update2: UpdateOperation<User> = {
	name: 'Bob',
	luckyNumber: REMOVE_FIELD
};

Type Parameters

BaseType extends object
definition: Exclude<[Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]> ? never : Key[keyof BaseType], undefined>