Improve QueryMatcher TypeScript definition (#7555)

This commit is contained in:
Michael Telatynski 2022-01-17 14:08:36 +00:00 committed by GitHub
parent 42adedc468
commit 5c44cb5cc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View file

@ -23,3 +23,14 @@ export type Writeable<T> = { -readonly [P in keyof T]: T[P] };
export type ComponentClass = keyof JSX.IntrinsicElements | JSXElementConstructor<any>; export type ComponentClass = keyof JSX.IntrinsicElements | JSXElementConstructor<any>;
export type ReactAnyComponent = React.Component | React.ExoticComponent; export type ReactAnyComponent = React.Component | React.ExoticComponent;
// 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] : "";

View file

@ -20,10 +20,11 @@ import { at, uniq } from 'lodash';
import { removeHiddenChars } from "matrix-js-sdk/src/utils"; import { removeHiddenChars } from "matrix-js-sdk/src/utils";
import { TimelineRenderingType } from '../contexts/RoomContext'; import { TimelineRenderingType } from '../contexts/RoomContext';
import { Leaves } from "../@types/common";
interface IOptions<T extends {}> { interface IOptions<T extends {}> {
keys: Array<string | keyof T>; keys: Array<Leaves<T>>;
funcs?: Array<(T) => string | string[]>; funcs?: Array<(o: T) => string | string[]>;
shouldMatchWordsOnly?: boolean; shouldMatchWordsOnly?: boolean;
// whether to apply unhomoglyph and strip diacritics to fuzz up the search. Defaults to true // whether to apply unhomoglyph and strip diacritics to fuzz up the search. Defaults to true
fuzzy?: boolean; fuzzy?: boolean;