diff --git a/src/utils/lazy.ts b/src/utils/lazy.ts index 87829fa44..01670d53c 100644 --- a/src/utils/lazy.ts +++ b/src/utils/lazy.ts @@ -5,12 +5,6 @@ */ import { UNCONFIGURABLE_PROPERTIES } from "./misc"; -import { AnyObject } from "./types"; - -export type ProxyLazy = T & { - [SYM_LAZY_GET]: () => T; - [SYM_LAZY_CACHED]: T | undefined; -}; export const SYM_LAZY_GET = Symbol.for("vencord.lazy.get"); export const SYM_LAZY_CACHED = Symbol.for("vencord.lazy.cached"); @@ -77,7 +71,7 @@ const handler: ProxyHandler = { * @param attempts How many times to try to evaluate the factory before giving up * @returns Result of factory function */ -export function proxyLazy(factory: () => T, attempts = 5): ProxyLazy { +export function proxyLazy(factory: () => T, attempts = 5): T { const get = makeLazy(factory, attempts, { isIndirect: true }); const proxyDummy = Object.assign(function () { }, { diff --git a/src/utils/proxyInner.ts b/src/utils/proxyInner.ts index 676a50f07..a5e12fbe6 100644 --- a/src/utils/proxyInner.ts +++ b/src/utils/proxyInner.ts @@ -5,12 +5,6 @@ */ import { UNCONFIGURABLE_PROPERTIES } from "./misc"; -import { AnyObject } from "./types"; - -export type ProxyInner = T & { - [SYM_PROXY_INNER_GET]?: () => T; - [SYM_PROXY_INNER_VALUE]?: T | undefined; -}; export const SYM_PROXY_INNER_GET = Symbol.for("vencord.proxyInner.get"); export const SYM_PROXY_INNER_VALUE = Symbol.for("vencord.proxyInner.innerValue"); @@ -52,10 +46,10 @@ const handler: ProxyHandler = { * @param primitiveErr The error message to throw when the inner value is a primitive * @returns A proxy which will act like the inner value when accessed */ -export function proxyInner( +export function proxyInner( errMsg = "Proxy inner value is undefined, setInnerValue was never called.", primitiveErrMsg = "proxyInner called on a primitive value." -): [proxy: ProxyInner, setInnerValue: (innerValue: T) => void] { +): [proxy: T, setInnerValue: (innerValue: T) => void] { const proxyDummy = Object.assign(function () { }, { [SYM_PROXY_INNER_GET]: function () { if (proxyDummy[SYM_PROXY_INNER_VALUE] == null) { diff --git a/src/utils/types.ts b/src/utils/types.ts index 6360f93ac..8c24843f8 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -356,7 +356,3 @@ export type PluginNative Return extends Promise ? Return : Promise : never; }; - -export type AnyObject = Record & ((...args: any[]) => any) & { - new(...args: any[]): any; -}; diff --git a/src/webpack/api.tsx b/src/webpack/api.tsx index 437cb346c..47c48e346 100644 --- a/src/webpack/api.tsx +++ b/src/webpack/api.tsx @@ -8,8 +8,7 @@ import { lazyString, makeLazy, proxyLazy } from "@utils/lazy"; import { LazyComponent, LazyComponentType, SYM_LAZY_COMPONENT_INNER } from "@utils/lazyReact"; import { Logger } from "@utils/Logger"; import { canonicalizeMatch } from "@utils/patches"; -import { ProxyInner, proxyInner, SYM_PROXY_INNER_VALUE } from "@utils/proxyInner"; -import { AnyObject } from "@utils/types"; +import { proxyInner, SYM_PROXY_INNER_VALUE } from "@utils/proxyInner"; import { traceFunction } from "../debug/Tracer"; import { GenericStore } from "./common"; @@ -200,7 +199,7 @@ export function waitFor(filter: FilterFn, callback: ModCallbackFn, { isIndirect * @param parse A function that takes the find result as its first argument and returns something to use as the proxy inner value. Useful if you want to use a value from the find result, instead of all of it. Defaults to the find result itself * @returns A proxy that has the parse function return value as its true value, or the plain parse function return value if it was called immediately. */ -export function find(filter: FilterFn, parse: (module: ModuleExports) => ModuleExports = m => m, { isIndirect = false }: { isIndirect?: boolean; } = {}) { +export function find(filter: FilterFn, parse: (module: ModuleExports) => ModuleExports = m => m, { isIndirect = false }: { isIndirect?: boolean; } = {}) { if (typeof filter !== "function") throw new Error("Invalid filter. Expected a function got " + typeof filter); if (typeof parse !== "function") @@ -213,7 +212,7 @@ export function find(filter: FilterFn, parse: (module: ModuleExpo webpackSearchHistory.push(["find", [proxy, filter]]); } - if (proxy[SYM_PROXY_INNER_VALUE] != null) return proxy[SYM_PROXY_INNER_VALUE] as ProxyInner; + if (proxy[SYM_PROXY_INNER_VALUE] != null) return proxy[SYM_PROXY_INNER_VALUE] as T; return proxy; } @@ -334,7 +333,7 @@ export function findComponentByCode(...code: string[] | * @param props A list of props to search the module or exports for * @param parse A function that takes the find result as its first argument and returns something. Useful if you want to use a value from the find result, instead of all of it. Defaults to the find result itself */ -export function findByProps(...props: string[] | [...string[], (module: ModuleExports) => T]) { +export function findByProps(...props: string[] | [...string[], (module: ModuleExports) => T]) { const parse = (typeof props.at(-1) === "function" ? props.pop() : m => m) as (module: ModuleExports) => T; const newProps = props as string[]; @@ -355,7 +354,7 @@ export function findByProps(...props: string[] | [...string[], (m * @param props A list of props to search the module or exports for * @param parse A function that takes the find result as its first argument and returns something. Useful if you want to use a value from the find result, instead of all of it. Defaults to the find result itself */ -export function findByPropsAndExtract(...props: string[] | [...string[], (module: ModuleExports) => T]) { +export function findByPropsAndExtract(...props: string[] | [...string[], (module: ModuleExports) => T]) { const parse = (typeof props.at(-1) === "function" ? props.pop() : m => m) as (module: ModuleExports) => T; const newProps = props as string[]; @@ -374,7 +373,7 @@ export function findByPropsAndExtract(...props: string[] | [...st * @param code A list of code to search each export for * @param parse A function that takes the find result as its first argument and returns something. Useful if you want to use a value from the find result, instead of all of it. Defaults to the find result itself */ -export function findByCode(...code: string[] | [...string[], (module: ModuleExports) => T]) { +export function findByCode(...code: string[] | [...string[], (module: ModuleExports) => T]) { const parse = (typeof code.at(-1) === "function" ? code.pop() : m => m) as (module: ModuleExports) => T; const newCode = code as string[]; @@ -408,7 +407,7 @@ export function findStore(name: string) { * @param code A list of code to search each factory for * @param parse A function that takes the find result as its first argument and returns something. Useful if you want to use a value from the find result, instead of all of it. Defaults to the find result itself */ -export function findByFactoryCode(...code: string[] | [...string[], (module: ModuleExports) => T]) { +export function findByFactoryCode(...code: string[] | [...string[], (module: ModuleExports) => T]) { const parse = (typeof code.at(-1) === "function" ? code.pop() : m => m) as (module: ModuleExports) => T; const newCode = code as string[]; @@ -436,7 +435,7 @@ export function findByFactoryCode(...code: string[] | [...string[ * @returns Unmangled exports as specified in mappers */ export function mapMangledModule(code: string | string[], mappers: Record) { - const mapping = {} as Record>; + const mapping = {} as Record; const setters = {} as Record void>; for (const newName in mappers) { @@ -494,7 +493,7 @@ export function findModuleFactory(...code: string[]) { const [proxy, setInnerValue] = proxyInner(`Webpack module factory find matched no module. Filter: ${printFilter(filter)}`, "Webpack find with proxy called on a primitive value."); waitFor(filter, (_, { factory }) => setInnerValue(factory)); - if (proxy[SYM_PROXY_INNER_VALUE] != null) return proxy[SYM_PROXY_INNER_VALUE] as ProxyInner; + if (proxy[SYM_PROXY_INNER_VALUE] != null) return proxy[SYM_PROXY_INNER_VALUE] as AnyModuleFactory; return proxy; } @@ -509,7 +508,7 @@ export function findModuleFactory(...code: string[]) { * @param attempts How many times to try to evaluate the factory before giving up * @returns Result of factory function */ -export function webpackDependantLazy(factory: () => T, attempts?: number) { +export function webpackDependantLazy(factory: () => T, attempts?: number) { if (IS_REPORTER) webpackSearchHistory.push(["webpackDependantLazy", [factory]]); return proxyLazy(factory, attempts);