@noaignite/centra-types
Version:
Typescript definitions for centra apis
42 lines (36 loc) • 1.16 kB
text/typescript
/**
* Return type `U` as long as it's shape is not empty, otherwise return type `T`.
*/
export type OverridableObject<T, U extends {}> = keyof U extends never ? T : U
/**
* Takes an object type and makes the hover overlay more readable.
* @see https://www.totaltypescript.com/concepts/the-prettify-helper
*/
export type Prettify<T> = {
[K in keyof T]: T[K]
} & {}
/**
* Remove properties `K` from `T`.
* Distributive for union types.
*/
export type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never
/**
* Like `T & U`, but using the value types from `U` where their properties overlap.
*/
export type Overwrite<T, U> = DistributiveOmit<T, keyof U> & U
/**
* Generate a set of string literal types with the given default record `T` and
* override record `U`.
*
* If the property value was `true`, the property key will be added to the
* string union.
*/
export type OverridableStringUnion<T extends string | number, U = {}> = GenerateStringUnion<
Overwrite<Record<T, true>, U>
>
type GenerateStringUnion<T> = Extract<
{
[Key in keyof T]: true extends T[Key] ? Key : never
}[keyof T],
string
>