/** * Copyright 2023 Fluence Labs Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Makes all properties in the object to be NOT readonly * Doesn't work recursively * * @example * const readonlyObject: Readonly<{a: number}> = { a: 1 }; * const mutableObject: Mutable = readonlyObject; * mutableObject.a = 2; */ export type Mutable = { -readonly [Key in keyof Type]: Type[Key]; }; /** * Makes particular object properties to be required * * @example * const object: { a?: number, b?: string, c?: boolean } = {}; * const requiredObject: WithRequired = { a: 1, b: "b" }; */ export type WithRequired = T & { [P in K]-?: T[P]; }; export type Flags = Record>; export type OptionalFlags = Partial>>; export declare const isObject: (unknown: unknown) => unknown is Record; export declare const hasKey: (key: K, unknown: unknown) => unknown is Record; /** * Asserts unknown value is an object that has the key * @example * const unknown: unknown = { a: 1 } * assertHasKey('a', unknown, 'unknown must have "a" key') * unknown // Record<'a', unknown> * @example * const unknown: unknown = { a: 1 } * assertHasKey('b', unknown, 'unknown must have "b" key') * // throws Error('unknown must have "b" key') * @param key any string key * @param unknown any value * @param message error message * @returns void */ export declare function assertHasKey(key: K, unknown: unknown, message?: string): asserts unknown is Record; /** * Returns a type guard (https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates) * that you can use to find out if unknown is a string union * @example * const isABC = getIsStringUnion(['a', 'b', 'c']) * * if (isABC(unknown)) { * unknown // 'a' | 'b' | 'c' * } * @param array ReadonlyArray\ * @returns (unknown: unknown) => unknown is Array\[number] */ export declare function getIsStringUnion(array: ReadonlyArray): (unknown: unknown) => unknown is Array[number];