/** * Gets a union type from an object that contains all combinations of nested keys as arrays. * * @example * ```ts * type Test = ObjectToKeyPaths<{ a: "foo"; b: { c: "bar"; d: "baz" } }>; * // type Test = ["a"] | ["b", "c"] | ["b", "d"] * ```; * * @see https://stackoverflow.com/a/47058976 */ type ObjectToKeyPaths = T extends string ? [] : { [K in Extract]: [K, ...ObjectToKeyPaths]; }[Extract]; /** * Joins the elements in the given type `T` with the separator `D`. * * @example * ```ts * type Test = Join<["foo", "bar"], ".">; * // type Test = "foo.bar" * ```; * * @see https://stackoverflow.com/a/47058976 */ type Join = T extends [] ? never : T extends [infer F] ? F : T extends [infer F, ...infer R] ? F extends string ? `${F}${D}${Join, D>}` : never : string; type NestedMessage = { [key: string]: string | NestedMessage; }; /** * Translation value. Can either by a string or nested object with more translation values. * * @example * ```ts * // simple value * { * someKey: "Hello World"; * } * * // nested value * { * someKey: { * someOtherKey: "Hello World"; * } * } * ```; */ export type TranslationValue = string | NestedMessage; /** * Gets a union type of deeply joined keys from an object. * * @example * ```ts * FlattenedKeysOf<{ * a: "test"; * b: { c: "test" }; * }>; * // results in: "a" | "b.c" * ```; * * @see https://stackoverflow.com/a/47058976 */ export type FlattenedKeysOf = Join, ".">; export {};