Update custom translations to support nested fields in structured JSON (#11685)
* Update matrix-web-i18n Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix custom translations for structured JSON nested fields Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix import Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix export Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update @matrix-org/react-sdk-module-api Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Delint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update matrix-web-i18n Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update matrix-web-i18n Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
1897962086
commit
632d8f4bc7
5 changed files with 74 additions and 108 deletions
|
@ -23,40 +23,7 @@ export type Writeable<T> = { -readonly [P in keyof T]: T[P] };
|
|||
|
||||
export type ComponentClass = keyof JSX.IntrinsicElements | JSXElementConstructor<any>;
|
||||
|
||||
/**
|
||||
* Utility type for string dot notation for accessing nested object properties.
|
||||
* Based on https://stackoverflow.com/a/58436959
|
||||
* @example
|
||||
* {
|
||||
* "a": {
|
||||
* "b": {
|
||||
* "c": "value"
|
||||
* },
|
||||
* "d": "foobar"
|
||||
* }
|
||||
* }
|
||||
* will yield a type of `"a.b.c" | "a.d"` with Separator="."
|
||||
* @typeParam Target the target type to generate leaf keys for
|
||||
* @typeParam Separator the separator to use between key segments when accessing nested objects
|
||||
* @typeParam LeafType the type which leaves of this object extend, used to determine when to stop recursion
|
||||
* @typeParam MaxDepth the maximum depth to recurse to
|
||||
* @returns a union type representing all dot (Separator) string notation keys which can access a Leaf (of LeafType)
|
||||
*/
|
||||
export type Leaves<Target, Separator extends string = ".", LeafType = string, MaxDepth extends number = 3> = [
|
||||
MaxDepth,
|
||||
] extends [never]
|
||||
? never
|
||||
: Target extends LeafType
|
||||
? ""
|
||||
: {
|
||||
[K in keyof Target]-?: Join<K, Leaves<Target[K], Separator, LeafType, Prev[MaxDepth]>, Separator>;
|
||||
}[keyof Target];
|
||||
type Prev = [never, 0, 1, 2, 3, ...0[]];
|
||||
type Join<K, P, S extends string = "."> = K extends string | number
|
||||
? P extends string | number
|
||||
? `${K}${"" extends P ? "" : S}${P}`
|
||||
: never
|
||||
: never;
|
||||
export type { Leaves } from "matrix-web-i18n";
|
||||
|
||||
export type RecursivePartial<T> = {
|
||||
[P in keyof T]?: T[P] extends (infer U)[]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue