Page Contents
Home > @loopback/repository-json-schema > Optional
Optional type
Optional: From T
make a set of properties by key K
become optional
Signature:
export type Optional<T extends object, K extends keyof T = keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
Example
type Props = {
name: string;
age: number;
visible: boolean;
};
// Expect: { name?: string; age?: number; visible?: boolean; }
type Props = Optional<Props>;
// Expect: { name: string; age?: number; visible?: boolean; }
type Props = Optional<Props, 'age' | 'visible'>;