From 82e41a5c275c5590759fe7748b3c1aad068e5ea2 Mon Sep 17 00:00:00 2001 From: Beef Date: Sat, 14 Jan 2023 16:05:08 +0000 Subject: [PATCH] [TS] Properly type RN.Platform.constants --- src/def.d.ts | 20 +++++++++++++++++++- src/lib/debug.ts | 4 ++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/def.d.ts b/src/def.d.ts index 3960ed0..1d34105 100644 --- a/src/def.d.ts +++ b/src/def.d.ts @@ -1,6 +1,6 @@ import * as _spitroast from "spitroast"; import _React from "react"; -import _RN from "react-native"; +import _RN, { PlatformConstants } from "react-native"; import _AsyncStorage from "@react-native-async-storage/async-storage"; type MetroModules = { [id: number]: any }; @@ -64,6 +64,24 @@ interface Settings { developerSettings: boolean; } +interface RNConstants extends PlatformConstants { + // Android + Version: number; + Release: string; + Serial: string; + Fingerprint: string; + Model: string; + Brand: string; + Manufacturer: string; + ServerHost?: string; + + // iOS + forceTouchAvailable: boolean; + interfaceIdiom: string; + osVersion: string; + systemName: string; +} + type Indexable = { [index: string]: Type } interface VendettaObject { diff --git a/src/lib/debug.ts b/src/lib/debug.ts index 0caa9a7..4b70b37 100644 --- a/src/lib/debug.ts +++ b/src/lib/debug.ts @@ -1,3 +1,4 @@ +import { RNConstants } from "@types"; import { ReactNative as RN } from "@metro/common"; import { after } from "@lib/patcher"; import { getAssetIDByName } from "@ui/assets"; @@ -48,8 +49,7 @@ export const versionHash = "__vendettaVersion"; export function getDebugInfo() { const InfoDictionaryManager = RN.NativeModules.InfoDictionaryManager; const hermesProps = window.HermesInternal.getRuntimeProperties(); - // TODO: Type 'any' removes errors, but is it sensible? - const PlatformConstants = RN.Platform.constants as any; + const PlatformConstants = RN.Platform.constants as RNConstants; const rnVer = PlatformConstants.reactNativeVersion; const DCDDeviceManager = RN.NativeModules.DCDDeviceManager;