diff --git a/src/globals.d.ts b/src/globals.d.ts index 4456564cc..f1a5a84bf 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -19,6 +19,8 @@ import { LoDashStatic } from "lodash"; declare global { + type AnyRecord = Record; + /** * This exists only at build time, so references to it in patches should insert it * via String interpolation OR use different replacement code based on this @@ -64,7 +66,7 @@ declare global { export var Vesktop: any; export var VesktopNative: any; - interface Window extends Record { + interface Window extends AnyRecord { _: LoDashStatic; } } diff --git a/src/plugins/accountPanelServerProfile/index.tsx b/src/plugins/accountPanelServerProfile/index.tsx index f7a901a90..cda6c6bc5 100644 --- a/src/plugins/accountPanelServerProfile/index.tsx +++ b/src/plugins/accountPanelServerProfile/index.tsx @@ -23,7 +23,7 @@ const UserProfile = findComponentByCode("UserProfilePopoutWrapper: user cannot b const styles = findByProps("accountProfilePopoutWrapper"); let openAlternatePopout = false; -let accountPanelRef: React.MutableRefObject | null> = { current: null }; +let accountPanelRef: React.MutableRefObject = { current: null }; const AccountPanelContextMenu = ErrorBoundary.wrap(() => { const { prioritizeServerProfile } = settings.use(["prioritizeServerProfile"]); diff --git a/src/plugins/userVoiceShow/components.tsx b/src/plugins/userVoiceShow/components.tsx index c8f65d01a..1eab9111b 100644 --- a/src/plugins/userVoiceShow/components.tsx +++ b/src/plugins/userVoiceShow/components.tsx @@ -17,7 +17,7 @@ const selectVoiceChannel = findProp("selectVoiceChannel", "selectChannel"); const VoiceStateStore = findStore("VoiceStateStore"); const UserSummaryItem = findComponentByCode("defaultRenderUser", "showDefaultAvatarsForNullUsers"); -interface IconProps extends React.HTMLAttributes { +interface IconProps extends React.ComponentPropsWithoutRef<"div"> { size?: number; } diff --git a/src/utils/lazyReact.tsx b/src/utils/lazyReact.tsx index 640f94edf..88cce9de3 100644 --- a/src/utils/lazyReact.tsx +++ b/src/utils/lazyReact.tsx @@ -6,10 +6,12 @@ import { makeLazy } from "./lazy"; -export type LazyComponentType = React.ComponentType & Record; - export const SYM_LAZY_COMPONENT_INNER = Symbol.for("vencord.lazyComponent.inner"); +export type LazyComponentType

= React.FunctionComponent

& AnyRecord & { + [SYM_LAZY_COMPONENT_INNER]: () => LazyComponentType

| null; +}; + /** * A lazy component. The factory method is called on first render. * @@ -17,15 +19,16 @@ export const SYM_LAZY_COMPONENT_INNER = Symbol.for("vencord.lazyComponent.inner" * @param attempts How many times to try to get the component before giving up * @returns Result of factory function */ -export function LazyComponent(factory: () => LazyComponentType, attempts = 5, errMsg: string | (() => string) = `LazyComponent factory failed:\n${factory}`) { +export function LazyComponent

(factory: () => any, attempts = 5, err: string | (() => string) = `LazyComponent factory failed:\n${factory}`): LazyComponentType

{ const get = makeLazy(factory, attempts, { isIndirect: true }); - let InnerComponent = null as LazyComponentType | null; + let InnerComponent = null as LazyComponentType

| null; let lazyFailedLogged = false; - const LazyComponent = (props: T) => { + const LazyComponent: LazyComponentType

= function (props) { if (!get.$$vencordLazyFailed()) { const ResultComponent = get(); + if (ResultComponent != null) { InnerComponent = ResultComponent; Object.assign(LazyComponent, ResultComponent); @@ -37,7 +40,7 @@ export function LazyComponent(factory: () => LazyCompone lazyFailedLogged = true; } - console.error(typeof errMsg === "string" ? errMsg : errMsg()); + console.error(typeof err === "string" ? err : err()); } return InnerComponent && ; @@ -45,5 +48,5 @@ export function LazyComponent(factory: () => LazyCompone LazyComponent[SYM_LAZY_COMPONENT_INNER] = () => InnerComponent; - return LazyComponent as LazyComponentType; + return LazyComponent; } diff --git a/src/webpack/api.tsx b/src/webpack/api.tsx index 780716263..c76f8bcd4 100644 --- a/src/webpack/api.tsx +++ b/src/webpack/api.tsx @@ -51,12 +51,13 @@ export type ModCallbackInfo = { factory: AnyModuleFactory; }; +export type FactoryListernFn = (factory: AnyModuleFactory) => void; export type ModListenerFn = (module: ModuleExports, info: ModListenerInfo) => void; export type ModCallbackFn = ((module: ModuleExports, info: ModCallbackInfo) => void) & { $$vencordCallbackCalled?: () => boolean; }; -export const factoryListeners = new Set<(factory: AnyModuleFactory) => void>(); +export const factoryListeners = new Set(); export const moduleListeners = new Set(); export const waitForSubscriptions = new Map(); @@ -170,16 +171,14 @@ function printFilter(filter: FilterFn) { return String(filter); } -function wrapWebpackComponent( - errMsg: string | (() => string) -): [WrapperComponent: LazyComponentType, setInnerComponent: (rawComponent: any, parsedComponent: LazyComponentType) => void] { - let InnerComponent = null as LazyComponentType | null; +function wrapWebpackComponent

(err: string | (() => string)): [WrapperComponent: LazyComponentType

, setInnerComponent: (rawComponent: any, parsedComponent: LazyComponentType

) => void] { + let InnerComponent = null as LazyComponentType

| null; let findFailedLogged = false; - const WrapperComponent = (props: T) => { + const WrapperComponent: LazyComponentType

= function (props) { if (InnerComponent === null && !findFailedLogged) { findFailedLogged = true; - logger.error(typeof errMsg === "string" ? errMsg : errMsg()); + logger.error(typeof err === "string" ? err : err()); } return InnerComponent && ; @@ -187,7 +186,7 @@ function wrapWebpackComponent( WrapperComponent[SYM_LAZY_COMPONENT_INNER] = () => InnerComponent; - function setInnerComponent(RawComponent: any, ParsedComponent: LazyComponentType) { + function setInnerComponent(RawComponent: any, ParsedComponent: LazyComponentType

) { InnerComponent = ParsedComponent; Object.assign(WrapperComponent, RawComponent); } @@ -282,7 +281,7 @@ export function find(filter: FilterFn, parse: (module: ModuleExports) = * @param parse A function that takes the found component as its first argument and returns a component. Useful if you want to wrap the found component in something. Defaults to the original component * @returns The component if found, or a noop component */ -export function findComponent(filter: FilterFn, parse: (component: ModuleExports) => LazyComponentType = m => m, { isIndirect = false }: { isIndirect?: boolean; } = {}) { +export function findComponent

(filter: FilterFn, parse: (component: ModuleExports) => LazyComponentType

= m => m, { isIndirect = false }: { isIndirect?: boolean; } = {}) { if (typeof filter !== "function") { throw new Error("Invalid filter. Expected a function got " + typeof filter); } @@ -290,14 +289,14 @@ export function findComponent(filter: FilterFn, parse: ( throw new Error("Invalid component parse. Expected a function got " + typeof parse); } - const [WrapperComponent, setInnerComponent] = wrapWebpackComponent(`Webpack find matched no module. Filter: ${printFilter(filter)}`); + const [WrapperComponent, setInnerComponent] = wrapWebpackComponent

(`Webpack find matched no module. Filter: ${printFilter(filter)}`); waitFor(filter, m => setInnerComponent(m, parse(m)), { isIndirect: true }); if (IS_REPORTER && !isIndirect) { webpackSearchHistory.push(["findComponent", [WrapperComponent, filter]]); } - if (WrapperComponent[SYM_LAZY_COMPONENT_INNER]() != null) return WrapperComponent[SYM_LAZY_COMPONENT_INNER]() as LazyComponentType; + if (WrapperComponent[SYM_LAZY_COMPONENT_INNER]() != null) return WrapperComponent[SYM_LAZY_COMPONENT_INNER]()!; return WrapperComponent; } @@ -312,20 +311,20 @@ export function findComponent(filter: FilterFn, parse: ( * @param parse A function that takes the found component as its first argument and returns a component. Useful if you want to wrap the found component in something. Defaults to the original component * @returns The component if found, or a noop component */ -export function findExportedComponent(...props: PropsFilter | [...PropsFilter, (component: ModuleExports) => LazyComponentType]) { - const parse = (typeof props.at(-1) === "function" ? props.pop() : m => m) as (component: ModuleExports) => LazyComponentType; +export function findExportedComponent

(...props: PropsFilter | [...PropsFilter, (component: ModuleExports) => LazyComponentType

]) { + const parse = (typeof props.at(-1) === "function" ? props.pop() : m => m) as (component: ModuleExports) => LazyComponentType

; const newProps = props as PropsFilter; const filter = filters.byProps(...newProps); - const [WrapperComponent, setInnerComponent] = wrapWebpackComponent(`Webpack find matched no module. Filter: ${printFilter(filter)}`); + const [WrapperComponent, setInnerComponent] = wrapWebpackComponent

(`Webpack find matched no module. Filter: ${printFilter(filter)}`); waitFor(filter, m => setInnerComponent(m[newProps[0]], parse(m[newProps[0]])), { isIndirect: true }); if (IS_REPORTER) { webpackSearchHistory.push(["findExportedComponent", [WrapperComponent, ...newProps]]); } - if (WrapperComponent[SYM_LAZY_COMPONENT_INNER]() != null) return WrapperComponent[SYM_LAZY_COMPONENT_INNER]() as LazyComponentType; + if (WrapperComponent[SYM_LAZY_COMPONENT_INNER]() != null) return WrapperComponent[SYM_LAZY_COMPONENT_INNER]()!; return WrapperComponent; } @@ -340,11 +339,11 @@ export function findExportedComponent(...props: PropsFil * @param parse A function that takes the found component as its first argument and returns a component. Useful if you want to wrap the found component in something. Defaults to the original component * @returns The component if found, or a noop component */ -export function findComponentByCode(...code: CodeFilter | [...CodeFilter, (component: ModuleExports) => LazyComponentType]) { - const parse = (typeof code.at(-1) === "function" ? code.pop() : m => m) as (component: ModuleExports) => LazyComponentType; +export function findComponentByCode

(...code: CodeFilter | [...CodeFilter, (component: ModuleExports) => LazyComponentType

]) { + const parse = (typeof code.at(-1) === "function" ? code.pop() : m => m) as (component: ModuleExports) => LazyComponentType

; const newCode = code as CodeFilter; - const ComponentResult = findComponent(filters.componentByCode(...newCode), parse, { isIndirect: true }); + const ComponentResult = findComponent

(filters.componentByCode(...newCode), parse, { isIndirect: true }); if (IS_REPORTER) { webpackSearchHistory.push(["findComponentByCode", [ComponentResult, ...newCode]]); @@ -363,11 +362,11 @@ export function findComponentByCode(...code: CodeFilter * @param parse A function that takes the found component as its first argument and returns a component. Useful if you want to wrap the found component in something. Defaults to the original component * @returns The component if found, or a noop component */ -export function findComponentByFields(...fields: PropsFilter | [...PropsFilter, (component: ModuleExports) => LazyComponentType]) { - const parse = (typeof fields.at(-1) === "function" ? fields.pop() : m => m) as (component: ModuleExports) => LazyComponentType; +export function findComponentByFields

(...fields: PropsFilter | [...PropsFilter, (component: ModuleExports) => LazyComponentType

]) { + const parse = (typeof fields.at(-1) === "function" ? fields.pop() : m => m) as (component: ModuleExports) => LazyComponentType

; const newFields = fields as PropsFilter; - const ComponentResult = findComponent(filters.componentByFields(...newFields), parse, { isIndirect: true }); + const ComponentResult = findComponent

(filters.componentByFields(...newFields), parse, { isIndirect: true }); if (IS_REPORTER) { webpackSearchHistory.push(["findComponentByCode", [ComponentResult, ...newFields]]); @@ -497,14 +496,14 @@ export function mapMangledModule(code: CodeFilterWithSing const mapperFilter = mappers[newName]; // Wrapper to select whether the parent factory filter or child mapper filter failed when the error is thrown - const errorMsgWrapper = () => `Webpack mapMangledModule ${callbackCalled ? "mapper" : "factory"} filter matched no module. Filter: ${printFilter(callbackCalled ? mapperFilter : factoryFilter)}`; + const errorWrapper = () => `Webpack mapMangledModule ${callbackCalled ? "mapper" : "factory"} filter matched no module. Filter: ${printFilter(callbackCalled ? mapperFilter : factoryFilter)}`; if (mapperFilter.$$vencordIsComponentFilter) { - const [WrapperComponent, setInnerComponent] = wrapWebpackComponent(errorMsgWrapper); + const [WrapperComponent, setInnerComponent] = wrapWebpackComponent(errorWrapper); mapping[newName] = WrapperComponent; wrapperComponentSetters[newName] = setInnerComponent; } else { - const [proxy, setInnerValue] = proxyInner(errorMsgWrapper, "Webpack find with proxy called on a primitive value. This may happen if you are trying to destructure a mapMangledModule primitive value on top level."); + const [proxy, setInnerValue] = proxyInner(errorWrapper, "Webpack find with proxy called on a primitive value. This may happen if you are trying to destructure a mapMangledModule primitive value on top level."); mapping[newName] = proxy; proxyInnerSetters[newName] = setInnerValue; } @@ -604,12 +603,12 @@ export function webpackDependantLazy(factory: () => T, attempts?: numbe * @param attempts How many times to try to get the component before giving up * @returns Result of factory function */ -export function webpackDependantLazyComponent(factory: () => any, attempts?: number) { +export function webpackDependantLazyComponent

(factory: () => any, attempts?: number) { if (IS_REPORTER) { webpackSearchHistory.push(["webpackDependantLazyComponent", [factory]]); } - return LazyComponent(factory, attempts, `Webpack dependant LazyComponent factory failed:\n${factory}`); + return LazyComponent

(factory, attempts, `Webpack dependant LazyComponent factory failed:\n${factory}`); } export const DefaultExtractAndLoadChunksRegex = /(?:(?:Promise\.all\(\[)?(\i\.e\("?[^)]+?"?\)[^\]]*?)(?:\]\))?|Promise\.resolve\(\))\.then\(\i\.bind\(\i,"?([^)]+?)"?\)\)/; diff --git a/src/webpack/common/types/menu.d.ts b/src/webpack/common/types/menu.d.ts index e2f46d1a5..405e4fbb4 100644 --- a/src/webpack/common/types/menu.d.ts +++ b/src/webpack/common/types/menu.d.ts @@ -18,7 +18,7 @@ import type { ComponentType, CSSProperties, MouseEvent, PropsWithChildren, ReactNode, UIEvent } from "react"; -type RC = ComponentType>>; +type RC = ComponentType>; export interface Menu { Menu: RC<{ @@ -73,7 +73,7 @@ export interface Menu { renderValue?(value: number): string, }>; MenuSearchControl: RC<{ - query: string + query: string; onChange(query: string): void; placeholder?: string; }>; diff --git a/src/webpack/common/types/utils.d.ts b/src/webpack/common/types/utils.d.ts index f26325c2a..e8b01aed8 100644 --- a/src/webpack/common/types/utils.d.ts +++ b/src/webpack/common/types/utils.d.ts @@ -241,7 +241,7 @@ export interface Constants { export type ActiveView = LiteralUnion<"emoji" | "gif" | "sticker" | "soundboard", string>; -export interface ExpressionPickerStoreState extends Record { +export interface ExpressionPickerStoreState extends AnyRecord { activeView: ActiveView | null; lastActiveView: ActiveView | null; activeViewType: any | null; diff --git a/src/webpack/wreq.d.ts b/src/webpack/wreq.d.ts index a31529c88..63bd27942 100644 --- a/src/webpack/wreq.d.ts +++ b/src/webpack/wreq.d.ts @@ -72,7 +72,7 @@ export type WebpackRequire = ((moduleId: PropertyKey) => ModuleExports) & { // * }); // * @returns fromObject // */ - // es: (this: WebpackRequire, fromObject: Record, toObject: Record) => Record; + // es: (this: WebpackRequire, fromObject: AnyRecord, toObject: AnyRecord) => AnyRecord; /** * Creates an async module. A module that exports something that is a Promise, or requires an export from an async module. * @@ -132,7 +132,7 @@ export type WebpackRequire = ((moduleId: PropertyKey) => ModuleExports) & { * } * // exports is now { exportName: someExportedValue } (but each value is actually a getter) */ - d: (this: WebpackRequire, exports: Record, definiton: Record) => void; + d: (this: WebpackRequire, exports: AnyRecord, definiton: AnyRecord) => void; /** The chunk handlers, which are used to ensure the files of the chunks are loaded, or load if necessary */ f: ChunkHandlers; /**