2020-05-29 19:13:59 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2020-05-29 19:13:59 +01:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2020-05-29 19:13:59 +01:00
|
|
|
*/
|
|
|
|
|
|
2023-07-07 13:37:26 +01:00
|
|
|
import { JSXElementConstructor } from "react";
|
2020-07-29 12:43:35 -06:00
|
|
|
|
2024-03-20 14:27:29 +00:00
|
|
|
export type { NonEmptyArray, XOR, Writeable } from "matrix-js-sdk/src/matrix";
|
2020-07-29 12:43:35 -06:00
|
|
|
|
|
|
|
|
export type ComponentClass = keyof JSX.IntrinsicElements | JSXElementConstructor<any>;
|
2022-01-17 14:08:36 +00:00
|
|
|
|
2023-10-02 11:44:25 +01:00
|
|
|
export type { Leaves } from "matrix-web-i18n";
|
2022-01-17 14:08:36 +00:00
|
|
|
|
2022-10-05 01:28:57 -04:00
|
|
|
export type KeysStartingWith<Input extends object, Str extends string> = {
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
|
[P in keyof Input]: P extends `${Str}${infer _X}` ? P : never; // we don't use _X
|
|
|
|
|
}[keyof Input];
|
2023-03-10 14:55:06 +00:00
|
|
|
|
2023-04-26 10:36:00 +01:00
|
|
|
export type Defaultize<P, D> = P extends any
|
|
|
|
|
? string extends keyof P
|
|
|
|
|
? P
|
|
|
|
|
: Pick<P, Exclude<keyof P, keyof D>> &
|
|
|
|
|
Partial<Pick<P, Extract<keyof P, keyof D>>> &
|
|
|
|
|
Partial<Pick<D, Exclude<keyof D, keyof P>>>
|
|
|
|
|
: never;
|
|
|
|
|
|
2024-10-16 16:43:07 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
|
2023-04-26 10:36:00 +01:00
|
|
|
export type DeepReadonly<T> = T extends (infer R)[]
|
|
|
|
|
? DeepReadonlyArray<R>
|
|
|
|
|
: T extends Function
|
2024-01-02 18:56:39 +00:00
|
|
|
? T
|
|
|
|
|
: T extends object
|
|
|
|
|
? DeepReadonlyObject<T>
|
|
|
|
|
: T;
|
2024-10-16 16:43:07 +01:00
|
|
|
/* eslint-enable @typescript-eslint/no-unsafe-function-type */
|
2023-04-26 10:36:00 +01:00
|
|
|
|
|
|
|
|
interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {}
|
|
|
|
|
|
|
|
|
|
type DeepReadonlyObject<T> = {
|
|
|
|
|
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
|
|
|
|
};
|
2023-04-28 09:45:36 +01:00
|
|
|
|
|
|
|
|
export type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> & U[keyof U];
|
2024-12-23 20:25:15 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a union type of the keys of the input Object type whose values are assignable to the given Item type.
|
|
|
|
|
* Based on https://stackoverflow.com/a/57862073
|
|
|
|
|
*/
|
|
|
|
|
export type Assignable<Object, Item> = {
|
|
|
|
|
[Key in keyof Object]: Object[Key] extends Item ? Key : never;
|
|
|
|
|
}[keyof Object];
|