2020-05-29 18:13:59 +00:00
|
|
|
/*
|
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2021-07-15 20:19:07 +00:00
|
|
|
import React, { JSXElementConstructor } from "react";
|
2020-07-29 18:43:35 +00:00
|
|
|
|
2020-05-29 18:13:59 +00:00
|
|
|
// Based on https://stackoverflow.com/a/53229857/3532235
|
2021-06-29 12:11:58 +00:00
|
|
|
export type Without<T, U> = {[P in Exclude<keyof T, keyof U>]?: never};
|
2020-05-29 18:13:59 +00:00
|
|
|
export type XOR<T, U> = (T | U) extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
|
2020-07-01 22:51:12 +00:00
|
|
|
export type Writeable<T> = { -readonly [P in keyof T]: T[P] };
|
2020-07-29 18:43:35 +00:00
|
|
|
|
|
|
|
export type ComponentClass = keyof JSX.IntrinsicElements | JSXElementConstructor<any>;
|
2021-07-15 20:19:07 +00:00
|
|
|
export type ReactAnyComponent = React.Component | React.ExoticComponent;
|
2022-01-17 14:08:36 +00:00
|
|
|
|
|
|
|
// Based on https://stackoverflow.com/a/58436959
|
|
|
|
type Join<K, P> = K extends string | number ?
|
|
|
|
P extends string | number ?
|
|
|
|
`${K}${"" extends P ? "" : "."}${P}`
|
|
|
|
: never : never;
|
|
|
|
|
|
|
|
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...0[]];
|
|
|
|
|
|
|
|
export type Leaves<T, D extends number = 5> = [D] extends [never] ? never : T extends object ?
|
|
|
|
{ [K in keyof T]-?: Join<K, Leaves<T[K], Prev[D]>> }[keyof T] : "";
|