From 29f0ac83f8fb618759f9b6b54e912f12b3d5aaf6 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sat, 19 Jul 2025 17:15:51 +0300 Subject: [PATCH] tsc: fix builds & fix type errors --- package.json | 10 +++++----- src/Socket/chats.ts | 5 +++-- src/Socket/messages-recv.ts | 4 ++-- src/Socket/messages-send.ts | 4 ++-- src/Utils/auth-utils.ts | 6 +++--- tsconfig.build.json | 7 ++++++- tsconfig.json | 4 ++-- 7 files changed, 23 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 91a3712c..a9fe576a 100644 --- a/package.json +++ b/package.json @@ -21,19 +21,19 @@ "engine-requirements.js" ], "scripts": { - "build:all": "tsc && typedoc", + "build:all": "yarn build && yarn build:docs", "build:docs": "typedoc", - "build:tsc": "tsc", + "build": "tsc -P tsconfig.build.json", "changelog:last": "conventional-changelog -p angular -r 2", "changelog:preview": "conventional-changelog -p angular -u", "changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0", "example": "tsx ./Example/example.ts", "gen:protobuf": "sh WAProto/GenerateStatics.sh", "format": "prettier --write \"src/**/*.{ts,js,json,md}\"", - "lint": "eslint src --ext .js,.ts", + "lint": "tsc && eslint src --ext .js,.ts", "lint:fix": "yarn format && yarn lint --fix", - "prepack": "tsc", - "prepare": "tsc", + "prepack": "yarn build", + "prepare": "yarn build", "preinstall": "node ./engine-requirements.js", "release": "release-it", "test": "jest" diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index 5015bde3..02625ee5 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -4,6 +4,7 @@ import { proto } from '../../WAProto' import { DEFAULT_CACHE_TTLS, PROCESSABLE_HISTORY_TYPES } from '../Defaults' import type { BotListInfo, + CacheStore, ChatModification, ChatMutation, LTHashState, @@ -73,10 +74,10 @@ export const makeChatsSocket = (config: SocketConfig) => { const placeholderResendCache = config.placeholderResendCache || - new NodeCache({ + (new NodeCache({ stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour useClones: false - }) + }) as CacheStore) if (!config.placeholderResendCache) { config.placeholderResendCache = placeholderResendCache diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index ed7444cb..3c0b1117 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -83,13 +83,13 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { const msgRetryCache = config.msgRetryCounterCache || - new NodeCache({ + new NodeCache({ stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour useClones: false }) const callOfferCache = config.callOfferCache || - new NodeCache({ + new NodeCache({ stdTTL: DEFAULT_CACHE_TTLS.CALL_OFFER, // 5 mins useClones: false }) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 5f4cb2e3..a2669a29 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -75,7 +75,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { const userDevicesCache = config.userDevicesCache || - new NodeCache({ + new NodeCache({ stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes useClones: false }) @@ -237,7 +237,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { } for (const key in deviceMap) { - userDevicesCache.set(key, deviceMap[key]) + userDevicesCache.set(key, deviceMap[key]!) } } diff --git a/src/Utils/auth-utils.ts b/src/Utils/auth-utils.ts index b6e3bb15..7544538f 100644 --- a/src/Utils/auth-utils.ts +++ b/src/Utils/auth-utils.ts @@ -27,7 +27,7 @@ export function makeCacheableSignalKeyStore( ): SignalKeyStore { const cache = _cache || - new NodeCache({ + new NodeCache({ stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes useClones: false, deleteOnExpire: true @@ -42,7 +42,7 @@ export function makeCacheableSignalKeyStore( const data: { [_: string]: SignalDataTypeMap[typeof type] } = {} const idsToFetch: string[] = [] for (const id of ids) { - const item = cache.get(getUniqueId(type, id)) + const item = cache.get(getUniqueId(type, id)) as any if (typeof item !== 'undefined') { data[id] = item } else { @@ -68,7 +68,7 @@ export function makeCacheableSignalKeyStore( let keys = 0 for (const type in data) { for (const id in data[type as keyof SignalDataTypeMap]) { - cache.set(getUniqueId(type, id), data[type as keyof SignalDataTypeMap]![id]) + cache.set(getUniqueId(type, id), data[type as keyof SignalDataTypeMap]![id]!) keys += 1 } } diff --git a/tsconfig.build.json b/tsconfig.build.json index cc5774c0..c8559327 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,6 +1,11 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "noEmit": false + "noEmit": false, + "allowImportingTsExtensions": false, + "outDir": "lib", + "declaration": true, + "declarationMap": true, + "sourceMap": true } } diff --git a/tsconfig.json b/tsconfig.json index 284f7aca..76321ae3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "target": "ES2020", "module": "ESNext", "moduleResolution": "bundler", - "outDir": "dist", + "outDir": "lib", "declaration": true, "sourceMap": true, "declarationMap": true, @@ -35,5 +35,5 @@ "checkJs": false }, "include": ["src/**/*.ts"], - "exclude": ["node_modules", "src/Tests/*"] + "exclude": ["node_modules"] }