fix: optimize typechecking performance
This commit is contained in:
parent
66f376ca33
commit
6407b0518f
7 changed files with 22 additions and 25 deletions
|
|
@ -339,7 +339,7 @@ export namespace DiscordModules {
|
|||
variant?: TableRowVariant
|
||||
}
|
||||
|
||||
export type TableRow = FC<TableRowProps> & {
|
||||
export interface TableRow extends FC<TableRowProps> {
|
||||
Arrow: FC
|
||||
Icon: TableRowIcon
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import type { If } from '@revenge-mod/utils/types'
|
|||
import type { Metro } from '../../types'
|
||||
import type { Filter } from './filters'
|
||||
|
||||
export type RunFilterOptions = {
|
||||
export interface RunFilterOptions {
|
||||
/**
|
||||
* Whether to skip checking the default export.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -9,11 +9,14 @@ export type FilterResult<F> = F extends Filter<infer R, boolean> ? R : never
|
|||
|
||||
export type IsFilterWithExports<F> = F extends Filter<any, infer WE> ? WE : never
|
||||
|
||||
export type Filter<_Inferable = any, WithExports extends boolean = boolean> = If<
|
||||
WithExports,
|
||||
(id: Metro.ModuleID, exports: Metro.ModuleExports) => boolean,
|
||||
(id: Metro.ModuleID, exports?: undefined) => boolean
|
||||
> & {
|
||||
export interface Filter<_Inferable = any, WithExports extends boolean = boolean> {
|
||||
(
|
||||
...args: If<
|
||||
WithExports,
|
||||
[id: Metro.ModuleID, exports: Metro.ModuleExports],
|
||||
[id: Metro.ModuleID, exports?: never]
|
||||
>
|
||||
): boolean
|
||||
key: string
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +70,7 @@ export type ByProps = <T extends Record<string, any> = Record<string, any>>(
|
|||
* Filter modules by their exports having all of the specified properties.
|
||||
*
|
||||
* @param prop The property to check for.
|
||||
* @param props The rest of the properties to check for (optional).
|
||||
* @param props More properties to check for (optional).
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
|
|
@ -81,10 +84,7 @@ export const byProps = createFilterGenerator<Parameters<ByProps>>(
|
|||
props => `revenge.props(${props.join(',')})`,
|
||||
) as ByProps
|
||||
|
||||
export type WithoutProps = <T extends Record<string, any>, K extends string>(
|
||||
prop: K,
|
||||
...props: K[]
|
||||
) => Filter<Omit<T, K>, true>
|
||||
export type WithoutProps = <T extends Record<string, any>>(prop: string, ...props: string[]) => Filter<T, true>
|
||||
|
||||
/**
|
||||
* Filter modules by their exports having none of the specified properties.
|
||||
|
|
@ -98,9 +98,7 @@ export const withoutProps = createFilterGenerator<Parameters<WithoutProps>>(
|
|||
props => `revenge.withoutProps(${props.join(',')})`,
|
||||
) as WithoutProps
|
||||
|
||||
export type ByName = <T extends string | object>(
|
||||
name: T extends string ? T : T extends { name: string } ? T['name'] : string,
|
||||
) => Filter<T extends string ? { name: T } : T & { name: typeof name }, true>
|
||||
export type ByName = <T extends object = object>(name: string) => Filter<T, true>
|
||||
|
||||
/**
|
||||
* Filter modules by their exports having the specified name.
|
||||
|
|
@ -112,7 +110,7 @@ export type ByName = <T extends string | object>(
|
|||
* @example Auto-typing as object
|
||||
* ```ts
|
||||
* const SomeComponent = await findModule(byName('SomeComponent'))
|
||||
* // const SomeComponent: { name: 'SomeComponent' }
|
||||
* // const SomeComponent: object
|
||||
* ```
|
||||
*
|
||||
* @example Typing as function component
|
||||
|
|
@ -137,14 +135,13 @@ export const byName = createFilterGenerator<Parameters<ByName>>(
|
|||
([name]) => `revenge.name(${name})`,
|
||||
) as ByName
|
||||
|
||||
export type RelativeDependency = object & {
|
||||
export interface RelativeDependency {
|
||||
valueOf(): Metro.ModuleID
|
||||
r?: boolean
|
||||
}
|
||||
|
||||
export type ComparableDependencyMap = Array<
|
||||
Metro.ModuleID | RelativeDependency | undefined | ComparableDependencyMap
|
||||
> & {
|
||||
export interface ComparableDependencyMap
|
||||
extends Array<Metro.ModuleID | RelativeDependency | undefined | ComparableDependencyMap> {
|
||||
l?: boolean
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import type { Metro } from '../../types'
|
|||
import type { RunFilterReturnExportsOptions } from './_internal'
|
||||
import type { Filter, FilterResult } from './filters'
|
||||
|
||||
export type BaseFindModuleOptions = {
|
||||
export interface BaseFindModuleOptions {
|
||||
/**
|
||||
* Abort signal for the find.
|
||||
*/
|
||||
|
|
@ -191,7 +191,7 @@ export function findModuleByImportedPath<T>(path: string, options?: BaseFindModu
|
|||
})
|
||||
}
|
||||
|
||||
export type BaseFindModuleSyncOptions = BaseFindModuleOptions & ProxifyOptions
|
||||
export interface BaseFindModuleSyncOptions extends BaseFindModuleOptions, ProxifyOptions {}
|
||||
export type FindModuleSyncOptions<
|
||||
ReturnNamespace extends boolean = boolean,
|
||||
IncludeUninitialized extends boolean = boolean,
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import type { MaybeDefaultExportMatched } from '.'
|
|||
import type { Metro } from '../../types'
|
||||
import type { Filter, FilterResult } from './filters'
|
||||
|
||||
export type BaseLookupModulesOptions<IncludeUninitialized extends boolean = boolean> = RunFilterOptions & {
|
||||
export interface BaseLookupModulesOptions<IncludeUninitialized extends boolean = boolean> extends RunFilterOptions {
|
||||
/**
|
||||
* Whether to include initialized modules in the lookup.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import type { MaybeDefaultExportMatched } from '.'
|
|||
import type { Metro } from '../../types'
|
||||
import type { Filter, FilterResult } from './filters'
|
||||
|
||||
export type BaseWaitForModulesOptions<IncludeAll extends boolean = boolean> = {
|
||||
export interface BaseWaitForModulesOptions<IncludeAll extends boolean = boolean> {
|
||||
/**
|
||||
* Whether to include all modules, including ones with bad exports.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ const _proxifyHandler = {
|
|||
},
|
||||
} as ProxyHandler<object>
|
||||
|
||||
export type ProxifyOptions = {
|
||||
export interface ProxifyOptions {
|
||||
/**
|
||||
* The hint for the proxified value.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue