From 4437b9a55782ac4b213fb209f52378b839329c2a Mon Sep 17 00:00:00 2001 From: Dmitrii Kartashev Date: Thu, 25 Jul 2024 19:31:59 -0400 Subject: [PATCH] Boolean filter improvement alternative: TS upgrade (#4840) * upgrade typescript and use new feature * fix: typing error --- package.json | 2 +- src/components/dialogs/ThreadgateEditor.tsx | 4 +++- src/state/queries/post-feed.ts | 4 ++-- src/state/queries/threadgate.ts | 2 +- src/view/screens/Search/Explore.tsx | 2 +- yarn.lock | 8 ++++---- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 091fb2fd..91b427ae 100644 --- a/package.json +++ b/package.json @@ -270,7 +270,7 @@ "react-scripts": "^5.0.1", "react-test-renderer": "18.2.0", "ts-node": "^10.9.1", - "typescript": "^5.3.3", + "typescript": "^5.5.4", "url-loader": "^4.1.1", "webpack": "^5.75.0", "webpack-bundle-analyzer": "^4.10.1", diff --git a/src/components/dialogs/ThreadgateEditor.tsx b/src/components/dialogs/ThreadgateEditor.tsx index 92dd157b..90483b3a 100644 --- a/src/components/dialogs/ThreadgateEditor.tsx +++ b/src/components/dialogs/ThreadgateEditor.tsx @@ -74,7 +74,9 @@ function DialogContent({ const onPressAudience = (setting: ThreadgateSetting) => { // remove nobody - let newSelected = draft.filter(v => v.type !== 'nobody') + let newSelected: ThreadgateSetting[] = draft.filter( + v => v.type !== 'nobody', + ) // toggle const i = newSelected.findIndex(v => isEqual(v, setting)) if (i === -1) { diff --git a/src/state/queries/post-feed.ts b/src/state/queries/post-feed.ts index 62ea0f33..1d6ec80d 100644 --- a/src/state/queries/post-feed.ts +++ b/src/state/queries/post-feed.ts @@ -375,11 +375,11 @@ export function usePostFeedQuery( } return undefined }) - .filter((n?: T): n is T => Boolean(n)), + .filter(n => !!n), } return feedPostSlice }) - .filter((n?: T): n is T => Boolean(n)), + .filter(n => !!n), })), ], } diff --git a/src/state/queries/threadgate.ts b/src/state/queries/threadgate.ts index c05d1f56..8b6aeba6 100644 --- a/src/state/queries/threadgate.ts +++ b/src/state/queries/threadgate.ts @@ -33,6 +33,6 @@ export function threadgateViewToSettings( } return setting }) - .filter((n?: T): n is T => Boolean(n)) + .filter(n => !!n) return settings } diff --git a/src/view/screens/Search/Explore.tsx b/src/view/screens/Search/Explore.tsx index e9b74452..5510fbee 100644 --- a/src/view/screens/Search/Explore.tsx +++ b/src/view/screens/Search/Explore.tsx @@ -119,7 +119,7 @@ function LoadMore({ } return loadMoreItem }) - .filter((n?: T): n is T => Boolean(n)) + .filter(n => !!n) }, [item.items, moderationOpts]) if (items.length === 0) return null diff --git a/yarn.lock b/yarn.lock index b99f9634..675fda4c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -21378,10 +21378,10 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -typescript@^5.3.3: - version "5.3.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37" - integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw== +typescript@^5.5.4: + version "5.5.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba" + integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q== ua-parser-js@^0.7.33: version "0.7.35"