/** * @license * Copyright 2022 Google LLC * SPDX-License-Identifier: Apache-2.0 */ declare module Util { /** Make properties K in T optional. */ type MakeOptional = { [P in Exclude]: T[P] } & { [P in K]+?: T[P] } /** An object with the keys in the union K mapped to themselves as values. */ type SelfMap = { [P in K]: P; }; /** Make optional all properties on T and any properties on object properties of T. */ type RecursivePartial = // Recurse into arrays and tuples: elements aren't (newly) optional, but any properties they have are. T extends (infer U)[] ? RecursivePartial[] : // Recurse into objects: properties and any of their properties are optional. T extends object ? {[P in keyof T]?: RecursivePartial} : // Strings, numbers, etc. (terminal types) end here. T; /** Recursively makes all properties of T read-only. */ type Immutable = T extends Function ? T : T extends Array ? ImmutableArray : T extends Map ? ImmutableMap : T extends Set ? ImmutableSet : T extends object ? ImmutableObject : T // Intermediate immutable types. Prefer e.g. Immutable> over direct use. type ImmutableArray = ReadonlyArray>; type ImmutableMap = ReadonlyMap, Immutable>; type ImmutableSet = ReadonlySet>; type ImmutableObject = { readonly [K in keyof T]: Immutable; }; /** * Exclude void from T */ type NonVoid = T extends void ? never : T; /** Remove properties K from T. */ type StrictOmit = Pick>; /** Obtain the type of the first parameter of a function. */ type FirstParamType any> = T extends (arg1: infer P, ...args: any[]) => any ? P : never; /** * If `S` is a kebab-style string `S`, convert to camelCase. */ type KebabToCamelCase = S extends `${infer T}-${infer U}` ? `${T}${Capitalize>}` : S /** Returns T with any kebab-style property names rewritten as camelCase. */ type CamelCasify = { [K in keyof T as KebabToCamelCase]: T[K]; } type LowercaseFirst = S extends `${infer First}${infer Rest}` ? `${Lowercase}${Rest}` : S; } export default Util;