@adaptabletools/adaptable
Version:
Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
84 lines (83 loc) • 2.88 kB
TypeScript
/**
* Get the keys of FirstType without any keys of SecondType.
*/
type Without<FirstType, SecondType> = {
[KeyType in Exclude<keyof FirstType, keyof SecondType>]?: never;
};
/**
* Create a type that has mutually exclusive keys.
* No unique keys of FirstType can be used simultaneously with any unique keys of SecondType.
*
* Example:
* `const myVar: XOR<FirstType, SecondType>`
*
* @see https://github.com/maninak/ts-xor/tree/master#description
*/
export type XOR<FirstType, SecondType> = FirstType | SecondType extends object ? (Without<FirstType, SecondType> & SecondType) | (Without<SecondType, FirstType> & FirstType) : FirstType | SecondType;
/**
* Create a type where at least one of the properties of a type(can be any property) is required to exist.
* Optionally the set of required properties may be restricted with the second generic type.
*
* @example
* ```
*
* type Responder = {
* text?: () => string;
* json?: () => string;
* secure?: boolean;
* };
*
* const responder: RequireAtLeastOne<Responder> = {
* secure: true
* };
*
* const responder2: RequireAtLeastOne<Responder, 'text' | 'json'> = {
* json: () => '{"message": "ok"}'
* };
* ```
*
* @see https://stackoverflow.com/a/49725198
*/
export type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
}[Keys];
/** Similar to the builtin Extract, but checks the filter strictly */
export type StrictExtract<T, U extends Partial<T>> = Extract<T, U>;
/**
* DeepRequired
*
* from https://github.com/piotrwitek/utility-types
*
* @desc Required that works for deeply nested structure
* @example
* // Expect: {
* // first: {
* // second: {
* // name: string;
* // };
* // };
* // }
* type NestedProps = {
* first?: {
* second?: {
* name?: string;
* };
* };
* };
* type RequiredNestedProps = DeepRequired<NestedProps>;
*/
export type DeepRequired<T> = T extends (...args: any[]) => any ? T : T extends any[] ? _DeepRequiredArray<T[number]> : T extends object ? _DeepRequiredObject<T> : T;
export interface _DeepRequiredArray<T> extends Array<DeepRequired<NonUndefined<T>>> {
}
export type _DeepRequiredObject<T> = {
[P in keyof T]-?: DeepRequired<NonUndefined<T[P]>>;
};
export type NonUndefined<A> = A extends undefined ? never : A;
export declare const getTypedKeys: <T extends string>(input: Record<T, any>) => T[];
export type OneOf<T extends any[]> = T extends [infer Only] ? Only : T extends [infer A, infer B, ...infer Rest] ? OneOf<[XOR<A, B>, ...Rest]> : never;
export type ValueOf<T> = T[keyof T];
export type EnsureAllValues<T extends string> = {
[K in T]: K;
};
export type ExhaustiveList<T extends string> = (keyof EnsureAllValues<T>)[];
export {};