UNPKG

@selenite/commons

Version:

This typescript package provides a set of frequently used utilities, types and svelte actions for building projects with Typescript and Svelte.

27 lines (26 loc) 823 B
/** * Frequently used types and type helpers for TypeScript. * @module */ /** * Make selected properties in T optional. * @typeParam T - The type to make partial. * @typeParam K - The keys of T to make optional. */ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; /** * Get the return type of the toJSON method of an object. * @typeParam T - The object type. */ export type SaveData<T extends { toJSON: () => unknown; }> = ReturnType<T['toJSON']>; export type ArrayKeys<T> = { [K in keyof T]: T[K] extends unknown[] | undefined ? K : never; }[keyof T]; export type StringKeys<T> = { [K in keyof T]: T[K] extends string | undefined ? K : never; }[keyof T]; export type StringArrayKeys<T> = { [K in keyof T]: T[K] extends string[] | undefined ? K : never; }[keyof T];