Skip to content

OptionalKeys

Overview

Type OptionalKeys

Returns the keys of T that are optional.

See https://stackoverflow.com/questions/54520676/in-typescript-how-to-get-the-keys-of-an-object-type-whose-values-are-of-a-given and https://stackoverflow.com/questions/52984808/is-there-a-way-to-get-all-required-properties-of-a-typescript-object

@author Jonathan Olson <jonathan.olson@colorado.edu> @author Sam Reid (PhET Interactive Simulations)

import type { OptionalKeys } from 'scenerystack/phet-core';

{ [K in keyof T]-?: {} extends Pick<T, K> ? K : never }[keyof T]

Source Code

See the source for OptionalKeys.ts in the phet-core repository.