From 89b9fa7958bca273357e85e2d13b3b1ef773fd91 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Sun, 27 Apr 2025 20:47:50 +0700 Subject: [PATCH] chore(lib): migrate usage of `.d.ts` to `.ts` --- lib/modules/package.json | 4 +- lib/modules/types/discord.d.ts | 511 ------------------ ...{discord.native.d.ts => discord.native.ts} | 0 lib/modules/types/discord.ts | 85 +++ lib/modules/types/{index.d.ts => index.ts} | 2 - lib/modules/types/{metro.d.ts => metro.ts} | 2 +- lib/patcher/src/{types.d.ts => types.ts} | 2 +- lib/utils/package.json | 2 +- lib/utils/src/{types.d.ts => types.ts} | 0 9 files changed, 90 insertions(+), 518 deletions(-) delete mode 100644 lib/modules/types/discord.d.ts rename lib/modules/types/{discord.native.d.ts => discord.native.ts} (100%) create mode 100644 lib/modules/types/discord.ts rename lib/modules/types/{index.d.ts => index.ts} (58%) rename lib/modules/types/{metro.d.ts => metro.ts} (98%) rename lib/patcher/src/{types.d.ts => types.ts} (99%) rename lib/utils/src/{types.d.ts => types.ts} (100%) diff --git a/lib/modules/package.json b/lib/modules/package.json index 6b21e04..498d248 100644 --- a/lib/modules/package.json +++ b/lib/modules/package.json @@ -25,8 +25,8 @@ "default": "./src/native/discord.ts" }, "./types/*": { - "default": "./types/*.d.ts", - "types": "./types/*.d.ts" + "default": "./types/*.ts", + "types": "./types/*.ts" }, "./_/metro": { "default": "./src/metro/_internal.ts" diff --git a/lib/modules/types/discord.d.ts b/lib/modules/types/discord.d.ts deleted file mode 100644 index 56455eb..0000000 --- a/lib/modules/types/discord.d.ts +++ /dev/null @@ -1,511 +0,0 @@ -import type { ComponentProps, ComponentType, FC, JSX, ReactNode } from 'react' -import type { - ImageProps, - ImageSourcePropType, - ImageStyle, - PressableProps, - TextInputProps, - TextProps, - TextStyle, - ViewProps, - ViewStyle, -} from 'react-native' - -export namespace DiscordModules { - export interface ToastActionCreators { - open(options: { - /** - * The unique key for this toast (so they don't stack up) - */ - key: string - /** - * The text to display in the toast - */ - content?: string - /** - * @deprecated Likely deprecated, use `IconComponent` instead - */ - icon?: number | FC - IconComponent?: FC - /** - * The icon's color, same string format as ``'s color prop - */ - iconColor?: string - containerStyle?: ViewStyle - }) - close(): void - } - - export interface AlertActionCreators { - /** - * Opens an alert modal - * - * @param key The unique key for this alert (so they don't stack up) - * @param alert The JSX element to display in the alert. Usually an `AlertModal` component. - */ - openAlert(key: string, alert: JSX.Element): void - dismissAlerts(): void - } - - export interface ActionSheetActionCreators { - openLazy(sheet: Promise<{ default: T }>, key: string, props: ComponentProps): void - hideActionSheet(key?: string): void - } - - export namespace ActionSheet { - interface ShowSimpleActionSheetOption { - icon?: number - label: string - isDestructive?: boolean - disabled?: boolean - onPress?(): void - } - - function showSimpleActionSheet(options: { - key: string - header: { - title: string - icon?: ReactNode - onClose?(): void - } - options: SimpleActionSheetOption[] - }): void - } - - export interface FilePickerUtils { - handleDocumentSelection(options?: Options): Promise - } - - export namespace FilePickerUtils { - export type File = { - uri: string - name: string - type: string - size: number - fileCopyUri: string | null - } - - export type Options = { - pickMultiple?: boolean - } - } - - export interface LinkingUtils { - /** - * Shows an action sheet with options for the given URL - * @param options Options for the action sheet - */ - showLongPressUrlActionSheet(options: { - urlString: string - guildId: string - channelId: string - messageId: string - }): void - /** - * Opens a URL - * @param url The URL to open - * @param options Options for opening the URL - * @param options.allowExternal Whether to allow opening external URLs - * @param options.forceExternalBrowser Whether to force opening the URL in an external browser - */ - openURL(url: string, options?: { allowExternal: boolean; forceExternalBrowser: boolean }): void - /** - * Opens a deep link - * @param link The deep link to open - */ - openDeeplink(link?: string): void - } - - export namespace Flux { - export type DispatcherPayload = any - export type DispatcherDependency = any - - export interface Dispatcher { - _actionHandlers: unknown - _interceptors?: ((payload: DispatcherPayload) => undefined | boolean)[] - _currentDispatchActionType: undefined | string - _processingWaitQueue: boolean - _subscriptions: Record void>> - _waitQueue: unknown[] - addDependencies(node1: DispatcherDependency, node2: DispatcherDependency): void - dispatch(payload: DispatcherPayload): Promise - flushWaitQueue(): void - isDispatching(): boolean - register( - name: string, - actionHandler: Record void>, - storeDidChange: (e: DispatcherPayload) => boolean, - ): string - setInterceptor(interceptor?: (payload: DispatcherPayload) => undefined | boolean): void - /** - * Subscribes to an action type - * @param actionType The action type to subscribe to - * @param callback The callback to call when the action is dispatched - */ - subscribe(actionType: string, callback: (payload: DispatcherPayload) => void): void - /** - * Unsubscribes from an action type - * @param actionType The action type to unsubscribe from - * @param callback The callback to remove - */ - unsubscribe(actionType: string, callback: (payload: DispatcherPayload) => void): void - wait(cb: () => void): void - } - } - - export type InviteUtils = { - __stub?: any - } - - export type ClipboardUtils = typeof import('@react-native-clipboard/clipboard').default - - export type MessageUtils = { - __stub?: any - } - - /** - * Discord's logger - * - * Logs will be shown in the **Debug Logs** section in settings - */ - export class Logger { - static name: string - constructor(tag: string) - log(...args: unknown[]): void - error(...args: unknown[]): void - warn(...args: unknown[]): void - info(...args: unknown[]): void - debug(...args: unknown[]): void - time(...args: unknown[]): void - trace(...args: unknown[]): void - verbose(...args: unknown[]): void - } - - export namespace Styles { - export type TextType = 'heading' | 'text' - export type BasicTextSize = 'sm' | 'md' | 'lg' - export type BasicTextSizeWithExtraLarges = BasicTextSize | 'xl' | 'xxl' - export type TextSize = BasicTextSizeWithExtraLarges | 'xs' | 'xxs' - export type TextWeight = 'normal' | 'medium' | 'semibold' | 'bold' - export type TextWeightWithExtraBold = TextWeight | 'extrabold' - export type RedesignTextCategory = 'message-preview' | 'channel-title' - - export type TextVariant = - | `heading-${BasicTextSizeWithExtraLarges}/${TextWeightWithExtraBold}` - | `text-${TextSize}/${TextWeight}` - | `display-${BasicTextSize}` - | `redesign/${RedesignTextCategory}/${TextWeight}` - | 'redesign/heading-18/bold' - | 'eyebrow' - - export type TextStyleSheet = Record - export type CreateStylesFn = >( - styles: S, - ) => () => S - } - - export namespace Components { - export type BaseButtonProps = PressableProps & { - disabled?: boolean - size?: ButtonSize - variant?: - | 'primary' - | 'secondary' - | 'tertiary' - | 'destructive' - | 'active' - | 'primary-overlay' - | 'secondary-overlay' - loading?: boolean - grow?: boolean - scaleAmountInPx?: number - } - - // Buttons - export type ButtonSize = 'sm' | 'md' | 'lg' - export type Button = FC< - BaseButtonProps & { - icon?: number - loading?: boolean - iconPosition?: 'start' | 'end' - renderIcon?(): ReactNode - renderRightIcon?(): ReactNode - renderShine?(): ReactNode - renderLinearGradient?(): ReactNode - cornerRadius?: number - textStyle?: TextStyle - loadingColorLight?: string - loadingColorDark?: string - text: string - } - > - export type TwinButtons = FC - export type IconButton = FC< - BaseButtonProps & { - icon: number - label?: string - } - > - export type RowButton = FC - export type ImageButton = FC< - BaseButtonProps & { - image: ImageSourcePropType - } - > - export type FloatingActionButton = FC - - // Layouts - export type Stack = FC< - ViewProps & { - spacing?: number - direction?: 'vertical' | 'horizontal' - } - > - export type Card = FC< - ViewProps & { - start?: boolean - end?: boolean - variant?: 'primary' | 'secondary' - border?: 'faint' | 'normal' | 'strong' | 'subtle' - // TODO(modules/types) - shadow?: 'none' - children: ReactNode - } - > - export type PressableScale = FC - - // Inputs - export type TextFieldProps = { - onChange?: (value: string) => void - onBlur?: () => void - onFocus?: () => void - - leadingIcon?: () => JSX.Element - trailingIcon?: () => JSX.Element - leadingText?: string - trailingText?: string - description?: string - errorMessage?: string - - isDisabled?: boolean - focusable?: boolean - editable?: boolean - status?: TextFieldStatus - - defaultValue?: string - value?: string - - placeholder?: string - placeholderTextColor?: string - - maxLength?: number - multiline?: boolean - - autoFocus?: boolean - secureTextEntry?: boolean - returnKeyType?: TextInputProps['returnKeyType'] - isClearable?: boolean - - size?: TextFieldSize - style?: ViewStyle | ViewStyle[] - } - - export type TextFieldSize = 'sm' | 'md' | 'lg' - - export type TextFieldStatus = 'default' | 'error' - - export type TextInput = FC< - TextFieldProps & { - isRound?: boolean - label?: string - } - > - export type TextField = FC - export type TextArea = FC, 'multiline'>> - export type GhostInput = FC - - // Forms - export type FormSwitch = FC< - ViewProps & { - value: boolean - onValueChange(value: boolean): void - disabled?: boolean - } - > - export type FormRadio = FC - export type FormCheckbox = FC - - // Segmented controls - export type SegmentedControl = FC - export type SegmentedControlPages = FC - export type SegmentedControlStateArgs = { - initialSelectedIndex: number - onChange: (index: number) => void - } - export type SegmentedControlState = { - selectedIndex: number - } - - // Sheets - export type ActionSheet = FC<{ children: ReactNode }> - export type ActionSheetCloseButton = FC, 'variant' | 'onPress'>> - export type ActionSheetRow = FC & { - Icon: ActionSheetRowIcon - Group: ActionSheetRowGroup - } - export type ActionSheetRowIcon = TableRowIcon - export type ActionSheetRowGroup = TableRowGroup - export type ActionSheetSwitchRow = TableSwitchRow - // export type ActionSheetIconHeader = FC - // export type ActionSheetHeaderBar = FC - // export type BottomSheetTitleHeader = FC - - export type IconSize = - | 'extraSmall10' - | 'extraSmall' - | 'small' - | 'small20' - | 'medium' - | 'large' - | 'custom' - | 'refreshSmall16' - | 'small14' - - // Tables - export type TableRowVariant = 'default' | 'danger' - export type TableRowProps = { - label: string - subLabel?: string - icon?: ReactNode - trailing?: ReactNode - arrow?: boolean - onPress?: PressableProps['onPress'] - disabled?: boolean - draggable?: boolean - dragHandlePressableProps?: PressableProps - labelLineClamp?: number - subLabelLineClamp?: number - // TODO(modules/types) - start?: unknown - end?: unknown - variant?: TableRowVariant - } - export type TableRowGroupProps = { - title?: string - description?: string - hasIcons?: boolean - accessibilityLabel?: string - accessibilityRole?: string - children: ReactNode - } - export type TableRow = FC & { - Arrow: FC - Icon: TableRowIcon - } - export type TableSwitchRow = FC< - Omit & { - accessibilityHint?: string - value: boolean - onValueChange(value: boolean): void - } - > - export type TableRowGroup = FC - export type TableRowGroupTitle = FC<{ - title: string - }> - export type TableRowIconVariant = - | 'default' - | 'blurple' - | 'boosting-pink' - | 'status-online' - | 'status-idle' - | 'status-dnd' - | 'status-offline' - | 'xbox' - | 'playstation' - | 'danger' - | 'secondary' - | 'translucent' - export type TableRowIcon = FC<{ - source: ImageSourcePropType - variant?: TableRowIconVariant - }> - export type TableRadioGroup = FC< - TableRowGroupProps & { - onChange(value: T): void - } - > - export type TableCheckboxRow = FC< - Omit & { - accessibilityHint?: string - checked: boolean - // TODO(modules/types) - onPress: unknown - } - > - export type TableRadioRow = FC< - Omit & { - accessibilityHint?: string - value: T - } - > - export type TableRowTrailingText = FC<{ - text: string - }> - - // Alerts - export type AlertModal = FC<{ - title: string - content?: ReactNode - extraContent?: ReactNode - actions?: ReactNode - }> - export type AlertActionButton = Button - - // Menus - export type ContextMenu = FC<{ - title: ReactNode - triggerOnLongPress?: boolean - items: Array - align?: 'left' | 'right' | 'above' | 'below' - children: (props: Partial) => ReactNode - }> - - export type ContextMenuItem = { - label: string - IconComponent?: FC - variant?: 'default' | 'destructive' - action(): void - } - - // Other - export type Slider = FC<{ - value: number - step: number - minimumValue: number - maximumValue: number - onValueChange?: (value: number) => void - onSlidingStart?: () => void - onSlidingComplete?: () => void - startIcon?: ReactNode - endIcon?: ReactNode - }> - - export type Text = FC< - TextProps & { - variant?: DiscordModules.Styles.TextVariant - color?: string - style?: TextStyle - lineClamp?: number - ellipsizeMode?: 'head' | 'middle' | 'tail' | 'clip' - tabularNumbers?: boolean - children?: ReactNode - } - > - - export type IntlLink = FC<{ - target: string - children?: ReactNode - }> - } -} diff --git a/lib/modules/types/discord.native.d.ts b/lib/modules/types/discord.native.ts similarity index 100% rename from lib/modules/types/discord.native.d.ts rename to lib/modules/types/discord.native.ts diff --git a/lib/modules/types/discord.ts b/lib/modules/types/discord.ts new file mode 100644 index 0000000..99fc462 --- /dev/null +++ b/lib/modules/types/discord.ts @@ -0,0 +1,85 @@ +export namespace DiscordModules { + export namespace Flux { + export type DispatcherPayload = any + export type DispatcherDependency = any + + export interface StoreChangeCallbacks { + add(cb: () => void): void + addConditional(cb: () => boolean): void + listeners: Set<() => void> + remove(cb: () => void): void + has(cb: () => void): boolean + hasAny(): boolean + invokeAll(): void + } + + export type Store = T & { + addChangeListener(cb: () => void): void + removeChangeListener(cb: () => void): void + addReactChangeListener(cb: () => void): void + removeReactChangeListener(cb: () => void): void + addConditionalChangeListener(cb: () => boolean): void + + callback(cb: () => void): void + throttledCallback(): unknown + + getName(): string + + __getLocalVars?(): object + + _changeCallbacks: StoreChangeCallbacks + _isInitialized: boolean + _version: number + _reactChangeCallbacks: StoreChangeCallbacks + } + + export interface Dispatcher { + _actionHandlers: unknown + _interceptors?: ((payload: DispatcherPayload) => undefined | boolean)[] + _currentDispatchActionType: undefined | string + _processingWaitQueue: boolean + _subscriptions: Record void>> + _waitQueue: unknown[] + addDependencies(node1: DispatcherDependency, node2: DispatcherDependency): void + dispatch(payload: DispatcherPayload): Promise + flushWaitQueue(): void + isDispatching(): boolean + register( + name: string, + actionHandler: Record void>, + storeDidChange: (e: DispatcherPayload) => boolean, + ): string + setInterceptor(interceptor?: (payload: DispatcherPayload) => undefined | boolean): void + /** + * Subscribes to an action type + * @param actionType The action type to subscribe to + * @param callback The callback to call when the action is dispatched + */ + subscribe(actionType: string, callback: (payload: DispatcherPayload) => void): void + /** + * Unsubscribes from an action type + * @param actionType The action type to unsubscribe from + * @param callback The callback to remove + */ + unsubscribe(actionType: string, callback: (payload: DispatcherPayload) => void): void + wait(cb: () => void): void + } + } + + /** + * Discord's `Logger` class. + * + * Logs will be shown in the **Debug Logs** section in settings. + */ + export interface Logger { + new (tag: string): void + log(...args: unknown[]): void + error(...args: unknown[]): void + warn(...args: unknown[]): void + info(...args: unknown[]): void + debug(...args: unknown[]): void + time(...args: unknown[]): void + trace(...args: unknown[]): void + verbose(...args: unknown[]): void + } +} diff --git a/lib/modules/types/index.d.ts b/lib/modules/types/index.ts similarity index 58% rename from lib/modules/types/index.d.ts rename to lib/modules/types/index.ts index de4e0c1..3819c14 100644 --- a/lib/modules/types/index.d.ts +++ b/lib/modules/types/index.ts @@ -1,5 +1,3 @@ export * from './discord' export * from './discord.native' -export * from './filter' export * from './metro' -export * from './react-navigation' diff --git a/lib/modules/types/metro.d.ts b/lib/modules/types/metro.ts similarity index 98% rename from lib/modules/types/metro.d.ts rename to lib/modules/types/metro.ts index 82ed70b..bc717e7 100644 --- a/lib/modules/types/metro.d.ts +++ b/lib/modules/types/metro.ts @@ -48,7 +48,7 @@ export namespace Metro { export type Module = { id?: ModuleID - exports: Exports + exports: ModuleExports } export type ModuleList = Map diff --git a/lib/patcher/src/types.d.ts b/lib/patcher/src/types.ts similarity index 99% rename from lib/patcher/src/types.d.ts rename to lib/patcher/src/types.ts index 2afea0d..56708a9 100644 --- a/lib/patcher/src/types.d.ts +++ b/lib/patcher/src/types.ts @@ -1,6 +1,6 @@ type FiniteDomain = unknown extends ( Key extends unknown - ? {} extends Record + ? object extends Record ? unknown : never : never diff --git a/lib/utils/package.json b/lib/utils/package.json index 1de45e5..dd7eb34 100644 --- a/lib/utils/package.json +++ b/lib/utils/package.json @@ -25,7 +25,7 @@ "default": "./src/objects.ts" }, "./types": { - "types": "./src/types.d.ts" + "types": "./src/types.ts" } } } diff --git a/lib/utils/src/types.d.ts b/lib/utils/src/types.ts similarity index 100% rename from lib/utils/src/types.d.ts rename to lib/utils/src/types.ts