From 1b64419ef1405492a353e01c46400f834749c0f8 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sat, 11 May 2024 05:44:52 -0300 Subject: [PATCH] Make commons have proper ProxyInner typing --- src/webpack/common/components.ts | 11 ++--------- src/webpack/common/stores.ts | 20 ++++++-------------- src/webpack/common/types/components.d.ts | 7 +++++++ src/webpack/common/types/stores.d.ts | 15 +++++++++++++++ src/webpack/common/types/utils.d.ts | 15 ++++++++++++++- src/webpack/common/utils.ts | 12 +++--------- 6 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/webpack/common/components.ts b/src/webpack/common/components.ts index 774fa29bb..adb5a9974 100644 --- a/src/webpack/common/components.ts +++ b/src/webpack/common/components.ts @@ -42,8 +42,6 @@ export let ScrollerThin: t.ScrollerThin = NoopComponent; export let Clickable: t.Clickable = NoopComponent; export let Avatar: t.Avatar = NoopComponent; export let FocusLock: t.FocusLock = NoopComponent; -// token lagger real -/** css colour resolver stuff, no clue what exactly this does, just copied usage from Discord */ export let useToken: t.useToken; export const MaskedLink = findComponent(filters.componentByCode("MASKED_LINK)")); @@ -52,7 +50,7 @@ export const Flex = findComponent(filters.byProps("Justify", "Align export const OAuth2AuthorizeModal = findExportedComponent("OAuth2AuthorizeModal"); -export const Forms = find(filters.byProps("FormItem", "Button"), m => { +export const Forms = find(filters.byProps("FormItem", "Button"), m => { ({ useToken, Card, @@ -78,9 +76,4 @@ export const Forms = find(filters.byProps("FormItem", "Button"), m => { } = m); return m; -}) as { - FormTitle: t.FormTitle, - FormSection: t.FormSection, - FormDivider: t.FormDivider, - FormText: t.FormText, -}; +}); diff --git a/src/webpack/common/stores.ts b/src/webpack/common/stores.ts index ce1638b60..311d1c66e 100644 --- a/src/webpack/common/stores.ts +++ b/src/webpack/common/stores.ts @@ -16,8 +16,6 @@ * along with this program. If not, see . */ -import type * as Stores from "discord-types/stores"; - // eslint-disable-next-line path-alias/no-relative import { filters, find, findByProps, findStore } from "../webpack"; import * as t from "./types/stores"; @@ -33,28 +31,22 @@ export enum DraftType { ApplicationLauncherCommand = 3 } -export const MessageStore = findStore("MessageStore") as Omit & { - getMessages(chanId: string): any; -}; - // This is not actually a FluxStore export const PrivateChannelsStore = findByProps("openPrivateChannel"); export const PermissionStore = findStore("PermissionStore"); export const GuildChannelStore = findStore("GuildChannelStore"); export const ReadStateStore = findStore("ReadStateStore"); export const PresenceStore = findStore("PresenceStore"); +export const MessageStore = findStore("MessageStore"); export const GuildStore = findStore("GuildStore"); -export const UserStore = findStore("UserStore"); +export const UserStore = findStore("UserStore"); export const UserProfileStore = findStore("UserProfileStore"); -export const SelectedChannelStore = findStore("SelectedChannelStore"); +export const SelectedChannelStore = findStore("SelectedChannelStore"); export const SelectedGuildStore = findStore("SelectedGuildStore"); -export const ChannelStore = findStore("ChannelStore"); -export const GuildMemberStore = findStore("GuildMemberStore"); -export const RelationshipStore = findStore("RelationshipStore") as Stores.RelationshipStore & t.FluxStore & { - /** Get the date (as a string) that the relationship was created */ - getSince(userId: string): string; -}; +export const ChannelStore = findStore("ChannelStore"); +export const GuildMemberStore = findStore("GuildMemberStore"); +export const RelationshipStore = findStore("RelationshipStore"); export const EmojiStore = findStore("EmojiStore"); export const WindowStore = findStore("WindowStore"); diff --git a/src/webpack/common/types/components.d.ts b/src/webpack/common/types/components.d.ts index e82851aa4..1fcdddd0a 100644 --- a/src/webpack/common/types/components.d.ts +++ b/src/webpack/common/types/components.d.ts @@ -68,6 +68,13 @@ export type FormText = ComponentType & TextProps> & { Types: FormTextTypes; }; +type Forms = { + FormTitle: t.FormTitle, + FormSection: t.FormSection, + FormDivider: t.FormDivider, + FormText: t.FormText, +}; + export type Tooltip = ComponentType<{ text: ReactNode; children: FunctionComponent<{ diff --git a/src/webpack/common/types/stores.d.ts b/src/webpack/common/types/stores.d.ts index 8fcff338a..5095eb004 100644 --- a/src/webpack/common/types/stores.d.ts +++ b/src/webpack/common/types/stores.d.ts @@ -18,6 +18,7 @@ import { DraftType } from "@webpack/common"; import { Channel, Guild, Role } from "discord-types/general"; +import type * as Stores from "discord-types/stores"; import { FluxDispatcher, FluxEvents } from "./utils"; @@ -183,6 +184,20 @@ export class GuildStore extends FluxStore { getAllGuildRoles(): Record>; } +type MessageStore = t.FluxStore & Omit & { + getMessages(channelId: string): any; +}; + +type UserStore = t.FluxStore & Stores.UserStore; +type SelectedChannelStore = t.FluxStore & Stores.SelectedChannelStore; +type ChannelStore = t.FluxStore & Stores.ChannelStore; +type GuildMemberStore = t.FluxStore & Stores.GuildMemberStore; + +type RelationshipStore = t.FluxStore & Stores.RelationshipStore & { + /** Get the date (as a string) that the relationship was created */ + getSince(userId: string): string; +}; + export type useStateFromStores = ( stores: t.FluxStore[], mapper: () => T, diff --git a/src/webpack/common/types/utils.d.ts b/src/webpack/common/types/utils.d.ts index 16fe6e2dd..03317131d 100644 --- a/src/webpack/common/types/utils.d.ts +++ b/src/webpack/common/types/utils.d.ts @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import { Guild, GuildMember } from "discord-types/general"; +import { Channel, Guild, GuildMember, User } from "discord-types/general"; import type { ReactNode } from "react"; import type { FluxEvents } from "./fluxEvents"; @@ -227,3 +227,16 @@ export interface IconUtils { getApplicationIconSource: any; getAnimatableSourceWithFallback: any; } + +export interface UserUtils { + getUser: (id: string) => Promise; +} + +export interface UploadHandler { + promptToUpload: (files: File[], channel: Channel, draftType: Number) => void; +} + +export interface ApplicationAssetUtils { + fetchAssetIds: (applicationId: string, e: string[]) => Promise; +} + diff --git a/src/webpack/common/utils.ts b/src/webpack/common/utils.ts index 6b78ace91..f8340e2b1 100644 --- a/src/webpack/common/utils.ts +++ b/src/webpack/common/utils.ts @@ -16,8 +16,6 @@ * along with this program. If not, see . */ -import type { Channel, User } from "discord-types/general"; - // eslint-disable-next-line path-alias/no-relative import { _resolveReady, filters, find, findByCode, findByProps, waitFor } from "../webpack"; import type * as t from "./types/utils"; @@ -108,14 +106,10 @@ export function showToast(message: string, type = ToastType.MESSAGE) { }); } -export const UserUtils = findByProps("getUser", "fetchCurrentUser") as { getUser: (id: string) => Promise; }; -export const UploadHandler = findByProps("showUploadFileSizeExceededError", "promptToUpload") as { - promptToUpload: (files: File[], channel: Channel, draftType: Number) => void; -}; +export const UserUtils = findByProps("getUser", "fetchCurrentUser"); +export const UploadHandler = findByProps("showUploadFileSizeExceededError", "promptToUpload"); -export const ApplicationAssetUtils = findByProps("fetchAssetIds", "getAssetImage") as { - fetchAssetIds: (applicationId: string, e: string[]) => Promise; -}; +export const ApplicationAssetUtils = findByProps("fetchAssetIds", "getAssetImage"); export const Clipboard = findByProps("SUPPORTS_COPY", "copy");